Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let newEmployee = Object.assign(receivedEmployee, {id: uuid.generate()});
data[data.length] = newEmployee;
localStorage.setItem('employees', JSON.stringify(data));
connection.mockRespond(new Response(new ResponseOptions({
status: 200,
body: newEmployee
})));
return;
}
// update employee
if (connection.request.url.endsWith('/fake-backend/employees') &&
connection.request.method === RequestMethod.Put) {
let receivedEmployee = JSON.parse(connection.request.getBody());
let clonedEmployee = Object.assign({}, receivedEmployee);
let employeeWasFound = false;
data.some((element: Employee, index: number) => {
if (element.id === clonedEmployee.id) {
data[index] = clonedEmployee;
employeeWasFound = true;
return true;
}
});
if (!employeeWasFound) {
connection.mockRespond(new Response(new ResponseOptions({
status: 400,
body: 'Employee could not be updated because was not found'
})));
public put(url: string, data: any, apiName?: string, params?: any): Observable {
return this.request({
method: RequestMethod.Put,
url: url,
data: data,
params: params,
apiName: apiName
});
}
public put(uri: string, options?: RequestOptionsArgs) {
return this.request(uri, mergeOptions(options, RequestMethod.Put));
}
saveFields(contentTypeId: string, fields: DotCMSContentTypeLayoutRow[]): Observable {
return this.coreWebService
.requestView({
body: {
layout: fields
},
method: RequestMethod.Put,
url: `v3/contenttype/${contentTypeId}/fields/move`
})
.pipe(pluck('entity'));
}
lock(inode: string): Observable {
return this.coreWebService
.requestView({
method: RequestMethod.Put,
url: `content/lock/inode/${inode}`
})
.pipe(pluck('bodyJsonObject'));
}
public putData(baseUrl: string, data: any): Observable {
return this.coreWebService.requestView({
body: data,
method: RequestMethod.Put,
url: `${baseUrl}`
}).pluck('entity');
}
public put(url: string, body: any, options?: RequestOptionsArgs): Observable {
return this.requestHelper({ body: body, method: RequestMethod.Put, url: url }, options);
}
public put(url: string, body: any = null, success: Function=function(successful, data, res){}, error: Function=function(successful, msg, err){}): any {
return this.request(url, new RequestOptions({
method: RequestMethod.Put,
body: body
}), success, error);
}
public put(url: string, body: any, options?: RequestOptionsArgs): Observable {
return this.requestHelper({ body: body, method: RequestMethod.Put, url: this.constructUrl(url) }, options);
}