I have a problem removing data in my Nodejs app. I have 2 buttons in my ejs template that send the exactly same URL to server to remove 2 models: the first button:
<td class="td6"><a href="/myprojects/<%= project._id %>/cost/<%= labour._id %>/remove"><button type="button" class="btn btn-danger">Remove</button></a></td>
The second button:
<td class="td21"><a href="/myprojects/<%= project._id %>/cost/<%= tool._id %>/remove"><button type="button" class="btn btn-danger">Remove</button></a></td>
I also have exactly the same route for both for removing data. The first one working perfectly but the second one doesn't work at all:
first route:
app.get("/myprojects/:id/cost/:labour_id/remove", function(req, res){
Labour.findByIdAndRemove(req.params.labour_id, function(err){
if(err){
console.log(err);
}else{
Project.findById(req.params.id, function(err, foundProject){
if(err){
console.log(err);
}else{
res.redirect("/myprojects/" +req.params.id+ "/cost");
}
});
}
});
});
and the second route:
app.get("/myprojects/:id/cost/:tool_id/remove", function(req, res){
Tool.findByIdAndRemove(req.params.tool_id, function(err){
if(err){
console.log(err);
}else{
Project.findById(req.params.id, function(err, foundProject){
if(err){
console.log(err);
}else{
res.redirect("/myprojects/" +req.params.id+ "/cost");
}
});
}
});
});
can anyone see any problem here?