Video 100: Resource Deleting Endpoints
This commit is contained in:
parent
2f22fb6be8
commit
0e37660afa
@ -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)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user