-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.txt
98 lines (74 loc) · 2.26 KB
/
test.txt
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// exports.checkData = (req, res, next) => {
// if (req.body.id > 2) {
// console.log('Your in');
// } else {
// return res.status(400).json({
// status: 'fail',
// message: "Sorry pls check your id !",
// });
// }
// next();
// };
// Adding changes to the original file
// fs.writeFile(
// `${__dirname}/../dev-data/data/tours-simple.json`,
// change,
// () => {
// res.status(200).json({
// status: 'success',
// data: {
// tour: newData,
// },
// });
// }
// );
// params will be vars in obj holding string so convert into number
// const id = +req.params.id;
// const resData = dataJson.find((el) => el.id === id);
// res.status(200).json({
// status: 'success',
// data: {
// tour: ,
// },
// });
Tours:
// exports.getSingleTour = catchAsync(async (req, res, next) => {
// const resData = await tours.findById(req.params.id).populate('reviews');
// if (!resData) {
// const err = new AppError(
// `Could not find any tour with that ID ${req.params.id}`,
// 404
// );
// return next(err);
// }
// res.status(200).json({
// status: 'success',
// data: resData,
// });
// });
// exports.deleteTour = catchAsync(async (req, res, next) => {
// const id = req.params.id;
// const deleteTour = await tours.deleteOne({ _id: id });
// if (!deleteTour.n) {
// const err = new AppError(
// `Could not find any tour with that ID ${req.params.id}`,
// 404
// );
// return next(err);
// }
// res.status(200).json({
// status: 'success',
// message: `Deleted the document with id ${id}`,
// });
// });
Reviews:
exports.getTopReviews = catchAsync(async (req, res) => {
// // const topReviews = await Review.find({ ratings: { $gt: 3 } }).limit(10);
// // const response = { status: 'success', topReviews };
// // if (topReviews.length === 0) response.topReviews = "No reviews available";
// // res.status(200).json(response);
// const topReviews = await Review.find().sort('-createdAt');
// const response = { status: 'success', topReviews };
// if (topReviews.length === 0) response.topReviews = "No reviews available";
// res.status(200).json(response);
// });