-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToDoController.js
More file actions
33 lines (26 loc) · 818 Bytes
/
Copy pathToDoController.js
File metadata and controls
33 lines (26 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const ToDoModel = require('../models/ToDoModel');
module.exports.getToDo = async (req, res) => {
const Todo = await ToDoModel.find();
res.send(Todo);
}
module.exports.saveToDo = async (req, res) => {
const { text } = req.body;
ToDoModel
.create({ text })
.then(() => res.set(201).send("Added Successfully..."))
.catch((err) => console.log(err))
}
module.exports.deleteToDo = (req, res) => {
const { _id } = req.body;
ToDoModel
.findByIdAndDelete(_id)
.then(() => res.set(201).send("Deleted Successfully..."))
.catch((err) => console.log(err))
}
module.exports.updateToDo = (req, res) => {
const { _id, text } = req.body;
ToDoModel
.findByIdAndUpdate(_id, {text})
.then(() => res.set(201).send("Updated Successfully..."))
.catch((err) => console.log(err))
}