todo CR todo list
This commit is contained in:
@@ -30,5 +30,33 @@ router.get('/list', async (req, res) => {
|
||||
res.send(getAnswer(null, items))
|
||||
})
|
||||
|
||||
router.post('/item', requiredValidate('todoId', 'title'), async (req, res) => {
|
||||
const { todoId, title } = req.body
|
||||
|
||||
const list = await ListModel.findById(todoId)
|
||||
|
||||
if (!list) {
|
||||
throw new Error('list not found')
|
||||
}
|
||||
|
||||
const userId = req.auth.id
|
||||
const item = await ItemModel.create({ title, createdBy: userId })
|
||||
|
||||
list.items.push(item)
|
||||
await list.save()
|
||||
})
|
||||
|
||||
router.get('/:todoId', async (req, res) => {
|
||||
const { todoId } = req.params
|
||||
|
||||
const list = await ListModel.findById(todoId).populate('items').exec()
|
||||
|
||||
if (!list) {
|
||||
throw new Error('list not found')
|
||||
}
|
||||
|
||||
res.send(getAnswer(null, list))
|
||||
})
|
||||
|
||||
|
||||
module.exports = router
|
||||
|
||||
Reference in New Issue
Block a user