From 0e37660afac7283cad751c17f50b6953b7222d52 Mon Sep 17 00:00:00 2001 From: JayWll Date: Sun, 23 Feb 2020 17:45:13 -0700 Subject: [PATCH] Video 100: Resource Deleting Endpoints --- task-manager/src/index.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/task-manager/src/index.js b/task-manager/src/index.js index 9e6c881..092f237 100644 --- a/task-manager/src/index.js +++ b/task-manager/src/index.js @@ -66,6 +66,20 @@ app.patch('/users/:id', async (req, res) => { } }) +app.delete('/users/:id', async (req, res) => { + try { + const user = await User.findByIdAndDelete(req.params.id) + + if (!user) { + return res.status(404).send() + } + + res.send(user) + } catch (e) { + res.status(500).send() + } +}) + app.post('/tasks', async (req, res) => { const task = new Task(req.body) @@ -124,6 +138,20 @@ app.patch('/tasks/:id', async (req, res) => { } }) +app.delete('/tasks/:id', async (req, res) => { + try { + const task = await Task.findByIdAndDelete(req.params.id) + + if (!task) { + return res.status(404).send() + } + + res.send(task) + } catch (e) { + res.status(500).send() + } +}) + app.listen(port, () => { console.log('Server is up on port ' + port) })