Skip to content

Commit

Permalink
Adds delete api for todos
Browse files Browse the repository at this point in the history
  • Loading branch information
DeadlockDruid committed Sep 24, 2018
1 parent 22387fe commit cffbe56
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ app.get('/todos/:id', (req, res) => {
}).catch((e) => res.status(400).send());
});

app.delete('/todos/:id', (req, res) => {
let id = req.params.id;

if (!ObjectID.isValid(id)) {
return res.status(404).send();
}

Todo.findByIdAndRemove(id).then((todo) => {
if (!todo) {
return res.status(404).send();
}

res.send(todo);
}).catch((e) => res.status(400).send());
});

app.listen(port, () => {
console.log(`Started on port: ${port}`);
});
Expand Down

0 comments on commit cffbe56

Please sign in to comment.