1
0
Fork 0

Video 100: Resource Deleting Endpoints

This commit is contained in:
JayWll 2020-02-23 17:45:13 -07:00
parent 2f22fb6be8
commit 0e37660afa
1 changed files with 28 additions and 0 deletions

View File

@ -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)
})