This commit is contained in:
2018-05-16 23:44:13 +03:00
parent b6a9bc4985
commit 5486b4582f
2 changed files with 18 additions and 18 deletions

View File

@@ -1,25 +1,25 @@
const express = require("express");
const mongoose = require("mongoose");
const express = require('express');
const mongoose = require('mongoose');
const router = express.Router();
const TodoList = mongoose.model("TodoList");
const Todo = mongoose.model("Todo");
const TodoList = mongoose.model('TodoList');
const Todo = mongoose.model('Todo');
const asyncHelper = require("../asyncHelper");
const asyncHelper = require('../asyncHelper');
// index
router.get(
"/",
'/',
asyncHelper(async (req, res) => {
const todos = await Todo.find({}).exec();
res.json(todos);
})
}),
);
// create
router.post(
"/",
'/',
asyncHelper(async (req, res) => {
const { text, listId } = req.body;
const list = await TodoList.findById(listId);
@@ -28,7 +28,7 @@ router.post(
list.todos.push(todo.id);
await list.save();
res.json({ success: true });
})
}),
);
module.exports = router;