Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let promise;
if (Request.printRequests) {
console.log(`\nSending ${this.type.toUpperCase()} Request: ${url}`);
console.log(`\tHeaders: ${JSON.stringify(headers, null, 2).replace(/(?:\r\n|\r|\n)/g, '\n\t')}`);
console.log(`\tParameters: ${JSON.stringify(this.parameters, null, 2).replace(/(?:\r\n|\r|\n)/g, '\n\t')}`);
console.log(`\tData: ${JSON.stringify(this.data, null, 2).replace(/(?:\r\n|\r|\n)/g, '\n\t')}\n`);
}
switch(this.type.toLowerCase()) {
case 'get':
promise = axios.get(url, { params: this.parameters, headers, withCredentials: true });
break;
case 'post':
promise = axios.post(url, this.data, { params: this.parameters, headers, withCredentials: true });
break;
case 'put':
promise = axios.put(url, this.data, { params: this.parameters, headers, withCredentials: true });
break;
case 'patch':
promise = axios.patch(url, this.data, { params: this.parameters, headers, withCredentials: true });
break;
case 'delete':
promise = axios.delete(url, { params: this.parameters, headers, withCredentials: true });
break;
default:
return reject(new Error('RequestError: Unknown type encountered during request.send execution. Type: ' + this.type + '.'));
}
if (promise !== undefined) {
promise.then((...args) => {
if (this.success !== undefined)
this.success(...args);
resolve(...args);
}).catch((...args) => {
save = () => {
this.setState({ saving: true });
const { resourceType, id } = this.props.match.params;
const { backendUrl } = this.props.settings;
axios
.put(
`${backendUrl}/${resourceType}/${id}?save_history`,
this.state.data,
{
headers: {
Authorization: `Bearer ${this.props.jwt.token}`
}
}
)
.then(() => {
this.setState({ saving: false });
this.props.messageToastr("Saved");
})
.catch(response => {
this.setState({ saving: false });
this.props.errorToastr(JSON.stringify(response.response.data));
submit = (model: UnitMeasureViewModel) => {
let mapper = new UnitMeasureMapper();
axios
.put(
Constants.ApiEndpoint +
ApiRoutes.UnitMeasures +
'/' +
this.state.model!.unitMeasureCode,
mapper.mapViewModelToApiRequest(model),
{
headers: {
'Content-Type': 'application/json',
},
}
)
.then(
resp => {
let response = resp.data as CreateResponse<
Api.UnitMeasureClientRequestModel
handleAddUser = () => {
const { csrf, onUserAdded, project } = this.props;
const { name, email } = this.state;
const fieldsValidation = {
email: StringHelper.validateEmail(email),
name: StringHelper.validateName(name),
};
if (Object.values(fieldsValidation).every(valid => !!valid)) {
this.setState({
statusClass: cs.infoMessage,
statusMessage: "Sending invitation",
});
axios
.put(`/projects/${project.id}}/add_user`, {
user_name_to_add: name,
user_email_to_add: email,
authenticity_token: csrf,
})
.then(() => {
onUserAdded(name, email);
this.setState({
statusClass: cs.successMessage,
statusMessage: "Invitation sent! User added.",
name: "",
email: "",
});
});
} else {
let invalidFieldsString = Object.keys(fieldsValidation)
const put = (url, data, options = {}) => {
const abort = Axios.CancelToken.source();
const id = setTimeout(() => abort.cancel(`Timeout of ${config.timeout}ms.`), config.timeout);
return Axios.put(url, data, { cancelToken: abort.token, ...options }).then((response) => {
clearTimeout(id);
return response;
});
};
sendUpdate() {
const data = {
city: this.city,
email: this.email,
makePublic: this.makePublic
}
const config = {
headers: {
'Authorization': `Bearer ${DataStore.token()}`
}
}
axios
.put(`http://localhost:4000/api/v1/${DataStore.username()}`, data, config)
.then(() => this.refreshData())
.catch(err => {
this.alertMessage = err.message
this.refreshFromDataStore()
})
}
},
.then(res => {
commentObj.id = res.data.name;
const repliedObj = { user_id: this.userId };
axios
.put(
this.baseURL +
"/commentsGrid/" +
this.nodeName +
"/replys/" +
commentObj.id +
".json" +
"?auth=" +
this.idToken,
repliedObj
)
.then(res => {
commentObj.depth =
"commentsGrid/" +
this.nodeName +
"/comments/" +
}).then(res => {
const options = {
headers: {
'Content-Type': file.type
}
};
return axios.put(res.data.url, file, options);
}).then(res => {
const {name} = res.config.data;
return dispatch => {
dispatch(requestAddToken());
let token = '';
let browser = '';
if (typeof window !== 'undefined' && typeof localStorage !== 'undefined') {
token = localStorage.getItem('id_token');
browser = localStorage.getItem('id_browser');
}
const api = WEB_API + '/api/tokens/' + addingToken;
return axios.put(
api,
{
headers: {
'Authorization': token,
'User-Client': browser,
'Content-Type': 'application/x-www-form-urlencode',
'Access-Control-Allow-Origin': '*',
'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=-1, private'
},
validateStatus: (status) => status >= 200 && status <= 500
}
)
.then(response => {
if (response.status === 200) {
dispatch(receiveAddToken(response.data));
} else if (response.status === 401) {
function updateResource (url, data) {
return axios.put(url, data)
}