1
0

Video 119: Filtering Data

This commit is contained in:
JayWll 2020-07-16 12:02:36 -06:00
parent c2d465adc8
commit d1eae33cfb

View File

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