Video 119: Filtering Data
This commit is contained in:
parent
c2d465adc8
commit
d1eae33cfb
@ -17,9 +17,19 @@ router.post('/tasks', auth, async (req, res) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// GET /tasks?completed=true
|
||||||
router.get('/tasks', auth, async (req, res) => {
|
router.get('/tasks', auth, async (req, res) => {
|
||||||
|
const match = {}
|
||||||
|
|
||||||
|
if (req.query.completed) {
|
||||||
|
match.completed = req.query.completed === 'true'
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await req.user.populate('tasks').execPopulate()
|
await req.user.populate({
|
||||||
|
path: 'tasks',
|
||||||
|
match
|
||||||
|
}).execPopulate()
|
||||||
res.send(req.user.tasks)
|
res.send(req.user.tasks)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(500).send()
|
res.status(500).send()
|
||||||
|
Loading…
Reference in New Issue
Block a user