when I click delete button I find particular data with id in chrome dev. tool but never delete data from database. I get an error like
DELETE http://localhost:3000/employee/5c29b718b9bc521ef8a91c3b 500 (Internal Server Error) core.js:14597 ERROR HttpErrorResponse {headers: HttpHeaders, status: 500, statusText: "Internal Server Error", url: "http://localhost:3000/employee/5c29b718b9bc521ef8a91c3b", ok: false, …}
controller file (node):
router.delete('/:id', (req,res) => {
if(!objectId.isValid(res.params.id)){
return res.status(400).send(`no record found for given id : ${ $res.params.id }`);
} else {
Employee.findByIdAndDelete(req.body.id, (error,docs) => {
if(!error)
{
res.send(docs);
} else {
console.log('Error in employee Delete :' + JSON.stringify(error,undefined,2));
}
});
}
});
service file (angular)enter code here
component.ts file (angular)
deleteEmployee(_id:string)
{
return this.http.delete(this.baseURL + `/${_id}`);
}
// delete employee
onDelete(_id: string,form :NgForm){
if(confirm('are you sure remove this data .. ?') == true){
this.employeeService.deleteEmployee(_id).subscribe((res) => {
this.refreshEmployeeList();
this.resetForm(form);
M.toast({html: 'delete sucessfully', classes: 'rounded'});
});
}
}