Skip to content

Commit 6581301

Browse files
committed
fixed minor bugs
1 parent 917d77b commit 6581301

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

routers/task.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,27 @@ router.get('/tasks', auth, async (req, res) => {
2727

2828
const match = {
2929
...query,
30-
limit: parseInt(req.query.limit),
31-
skip: parseInt(req.query.skip),
30+
limit: req.query.limit === undefined ? 0 : parseInt(req.query.limit),
31+
skip: req.query.skip === undefined ? 0 : parseInt(req.query.skip),
3232
sort: req.query.sortBy ? { [req.query.sortBy.split('_')[0]]: req.query.sortBy.split('_')[1] === 'desc' ? -1 : 1 } : {}
3333
}
3434

3535
try {
3636

3737
if (req.query.completed) {
38-
const tasks = req.user ? await Task
38+
const tasks = await Task
3939
.find({ owner: req.user._id, completed: req.query.completed === 'true' })
40-
.limit(parseInt(match.limit))
41-
.skip(parseInt(match.skip))
42-
.sort(match.sort) : []
40+
.limit(match.limit)
41+
.skip(match.skip)
42+
.sort(match.sort)
4343
res.send(tasks)
4444
} else {
45-
const tasks = req.user ? await Task
45+
const tasks = await Task
4646
.find({ owner: req.user._id })
47-
.limit(parseInt(match.limit))
48-
.skip(parseInt(match.skip))
49-
.sort(match.sort) : []
47+
.limit(match.limit)
48+
.skip(match.skip)
49+
.sort(match.sort)
50+
5051
res.send(tasks)
5152
}
5253
} catch (e) {

0 commit comments

Comments
 (0)