-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.js
47 lines (42 loc) · 1013 Bytes
/
router.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
const express = require("express");
const router = express.Router();
const InfoRouter = require("./infoSchema");
//post
router.post("/", async (req, res) => {
var data = new InfoRouter({
Name: req.body.Name,
Author: req.body.Author,
Rating: req.body.Rating,
});
await data.save();
res.json(data);
});
//getall
router.get("/", async (req, res) => {
var findData = await InfoRouter.find();
res.json(findData);
});
//update
router.put("/update", async (req, res) => {
var update = await InfoRouter.update(
{ _id: req.body._id },
{
$set: {
Name: req.body.Name,
Author: req.body.Author,
Rating: req.body.Rating,
},
}
);
res.json(update);
});
//delete
router.delete("/del/:id", async (req, res) => {
var del = await InfoRouter.findByIdAndRemove(req.params.id).then((e) => {
res.json({ messAuthor: "deleted successfully" });
});
});
router.get("/", (req, res) => {
res.json("Im from router file");
});
module.exports = router;