reviews.js
1.66 KB
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
const router = require('express').Router();
const Review = require('../models/review');
// Find All
router.get('/', (req, res) => {
Review.findAll()
.then((Reviews) => {
if (!Reviews.length) return res.status(404).send({ err: 'Review not found' });
res.send(`find successfully: ${Reviews}`);
})
.catch(err => res.status(500).send(err));
});
// Find One by Reviewid
router.get('/lecturename/:lecturename', (req, res) => {
Review.findBylecturename(req.params.lecturename)
.then((Review) => {
if (!Review) return res.status(404).send({ err: 'Review not found' });
res.send(`findOne successfully: ${Review}`);
})
.catch(err => res.status(500).send(err));
});
router.get('/proname/:proname', (req, res) => {
Review.findByproname(req.params.proname)
.then((Review) => {
if (!Review) return res.status(404).send({ err: 'Review not found' });
res.send(`findOne successfully: ${Review}`);
})
.catch(err => res.status(500).send(err));
});
// Create new Review document
router.post('/', (req, res) => {
console.log(req.body)
Review.create(req.body)
.then(Review => res.send(Review))
.catch(err => res.status(500).send(err));
});
// Update by lecturename
router.put('/lecturename/:lecturename', (req, res) => {
Review.updateBylecturename(req.params.lecturename, req.body)
.then(Review => res.send(Review))
.catch(err => res.status(500).send(err));
});
// Delete by lecturename
router.delete('/lecturename/:lecturename', (req, res) => {
Review.deleteBylecturename(req.params.lecturename)
.then(() => res.sendStatus(200))
.catch(err => res.status(500).send(err));
});
module.exports = router;