-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.js
55 lines (53 loc) · 1.27 KB
/
controller.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
const model = require('./model');
module.exports = {
getReviews: (req, res) => {
const { count, page, product_id } = req.query;
const count1 = count || 5;
const page1 = page || 1;
model.getAllReviews(product_id, count1, page1)
.then((results) => {
res.json({
product: product_id,
page: page1,
count: count1,
results: results.rows,
});
})
.catch((err) => {
res.status(404).send(err);
});
},
postReview: (req, res) => {
const {
product_id, rating, summary, body, recommend,
reviewer_name, reviewer_email, photos, characteristics,
} = req.body;
model.postReview(
product_id,
rating,
summary,
body,
recommend,
reviewer_name,
reviewer_email,
photos,
characteristics,
)
.then(() => {
res.status(201).send('A review has been added.');
})
.catch((err) => {
res.status(404).send(err);
});
},
getMeta: (req, res) => {
const { product_id } = req.query;
model.getMetaData(product_id)
.then((results) => {
res.status(201).send(results.rows[0].json_build_object);
})
.catch((err) => {
res.status(404).send(err);
});
},
};