mirror of
https://github.com/usatiuk/ustk-todolist.git
synced 2025-10-28 23:57:49 +01:00
index and create todos and lists
This commit is contained in:
32
routes/lists.js
Normal file
32
routes/lists.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const express = require("express");
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
const TodoList = mongoose.model("TodoList");
|
||||
|
||||
const asyncHelper = require("../asyncHelper");
|
||||
|
||||
// index
|
||||
router.get(
|
||||
"/",
|
||||
asyncHelper(async (req, res) => {
|
||||
const lists = await TodoList.find({})
|
||||
.populate("todos")
|
||||
.exec();
|
||||
res.json(lists);
|
||||
})
|
||||
);
|
||||
|
||||
// create
|
||||
router.post(
|
||||
"/",
|
||||
asyncHelper(async (req, res) => {
|
||||
const { name } = req.body;
|
||||
const newList = new TodoList({ name });
|
||||
await newList.save();
|
||||
res.json({ success: true });
|
||||
})
|
||||
);
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user