add offline support

This commit is contained in:
2018-06-26 19:44:27 +03:00
parent 3791d4a5d7
commit 4c0da92a1a
10 changed files with 165 additions and 100 deletions

View File

@@ -24,7 +24,8 @@ router.post(
'/',
asyncHelper(async (req, res) => {
const { name } = req.body;
const newList = new TodoList({ name, user: req.user.id });
const { id } = req.body || mongoose.Types.ObjectId();
const newList = new TodoList({ name, user: req.user.id, _id: id });
await newList.save();
res.json({ success: true, data: newList.toJson() });
}),

View File

@@ -26,7 +26,8 @@ router.post(
asyncHelper(async (req, res) => {
const { listId } = res.locals || req.body;
const { text } = req.body;
const todo = new Todo({ text, list: listId, user: req.user.id });
const { id } = req.body || mongoose.Types.ObjectId();
const todo = new Todo({ text, list: listId, user: req.user.id, _id: id });
await todo.save();
res.json({ success: true, data: todo.toJson() });
}),