-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathroute.js
61 lines (55 loc) · 1.19 KB
/
route.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
50
51
52
53
54
55
56
57
58
59
60
61
const express =require('express');
const router =express.Router();
const todoModel = require('./todoModel');
//localhost:300/api/listtodo/
router.get('/listtodo',(req,res)=>{
todoModel.find()
.exec()
.then(result=>{
res.status(200).json(result);
})
.catch(err=>{
res.status(500).json({
msg:"err"
})
})
})
//localhost:300/api/addtodo/
router.post('/addtodo',(req,res)=>{
let newtodo = new todoModel({
name:req.body.name,
type:req.body.type,
ver:req.body.ver
});
newtodo.save()
.then(result=>{
res.status(200).json({
msg:"success"
})
})
.catch(err=>{
res.status(500).json({
msg:"err"
})
})
})
//localhost:300/api/edittodo/
router.put('/edittodo',(req,res)=>{
res.json("edit todo");
})
//localhost:300/api/deletettodo/
router.delete('/deletetodo/:Id',(req,res)=>{
todoModel.findByIdAndRemove(req.params.Id)
.exec()
.then(result=>{
res.status(200).json({
msg:"success"
})
})
.catch(err=>{
res.status(500).json({
msg:"err"
})
})
})
module.exports = router;