-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.js
30 lines (25 loc) · 821 Bytes
/
view.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
const model = require("./Model");
exports.getAllEntry = async (req, res) => {
const newData = await model.find();
res.status(200).json({
result: true,
totalEntry: model.length,
data: newData,
});
};
exports.createEntry = async (req, res) => {
const newData = await model.create(req.body);
res.status(201).json(newData);
};
exports.getSingleEntry = async (req, res) => {
const newData = await model.findById(req.params.id);
res.status(200).json(newData);
};
exports.updateSingleEntry = async (req, res) => {
const newData = await model.findByIdAndUpdate(req.params.id, req.body);
res.status(200).json(newData);
};
exports.deleteSingleEntry = async (req, res) => {
const newData = await model.findByIdAndDelete(req.params.id, req.body);
res.status(200).json("Entry has been Deleted successfully");
};