index all todos

This commit is contained in:
2018-06-07 14:45:56 +03:00
parent 6f34bd1cab
commit e995b6cdbf
2 changed files with 14 additions and 1 deletions

View File

@@ -13,7 +13,9 @@ router.get(
'/',
asyncHelper(async (req, res) => {
const { listId } = res.locals || req.body;
const todos = await Todo.find({ list: listId, user: req.user.id }).exec();
const todos = listId
? await Todo.find({ list: listId, user: req.user.id }).exec()
: await Todo.find({ user: req.user.id }).exec();
res.json({ success: true, data: todos.map(todo => todo.toJson()) });
}),
);