1
0
Fork 0

Video 119: Filtering Data

This commit is contained in:
JayWll 2020-07-16 12:02:36 -06:00
parent c2d465adc8
commit d1eae33cfb
1 changed files with 11 additions and 1 deletions

View File

@ -17,9 +17,19 @@ router.post('/tasks', auth, async (req, res) => {
}
})
// GET /tasks?completed=true
router.get('/tasks', auth, async (req, res) => {
const match = {}
if (req.query.completed) {
match.completed = req.query.completed === 'true'
}
try {
await req.user.populate('tasks').execPopulate()
await req.user.populate({
path: 'tasks',
match
}).execPopulate()
res.send(req.user.tasks)
} catch (e) {
res.status(500).send()