-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskController.js
49 lines (44 loc) · 1.07 KB
/
TaskController.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import Task from "../models/TaskModel.js";
export const addTask = async (req, res, next) => {
try {
const task = new Task(req.body);
const savedTask = await task.save();
res.status(200).json(savedTask);
} catch (error) {
next(error);
}
};
export const getAllTask = async (req, res, next) => {
try {
const tasks = await Task.find();
res.status(200).json(tasks);
} catch (error) {
next(error);
}
};
export const getSingleTask = async (req, res, next) => {
try {
const task = await Task.findById(req.params.id);
res.status(200).json(task);
} catch (error) {
next(error);
}
};
export const updateTask = async (req, res, next) => {
try {
const updatedTask = await Task.findByIdAndUpdate(req.params.id, req.body, {
new: true,
});
res.status(200).json(updatedTask);
} catch (error) {
next(error);
}
};
export const deleteTask = async (req, res, next) => {
try {
const deletedTask = await Task.findByIdAndDelete(req.params.id);
res.status(200).json(deletedTask);
} catch (error) {
next(error);
}
};