-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrollerReview.js
More file actions
69 lines (63 loc) · 1.83 KB
/
Copy pathcontrollerReview.js
File metadata and controls
69 lines (63 loc) · 1.83 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const db = require('./database');
const getAllPubReview = async (req, res) => {
try {
const query = 'SELECT * FROM PubReview';
const [results] = await db.query(query);
res.json(results);
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Internal Server Error' });
}
};
const getPubReviewById = async (req, res) => {
try {
const id = req.params.id;
const query = 'SELECT * FROM PubReview WHERE User_id = ?';
const [results] = await db.query(query, [id]);
res.json(results);
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Internal Server Error' });
}
};
const createPubReview = async (req, res) => {
try {
const newPubReview = req.body;
const query = 'INSERT INTO PubReview SET ?';
const [results] = await db.query(query, [newPubReview]);
res.json({ id: results.insertId, ...newPubReview });
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Internal Server Error' });
}
};
const deletePubReview = async (req, res) => {
try {
const id = req.params.id;
const query = 'DELETE FROM PubReview WHERE User_id = ?';
await db.query(query, [id]);
res.json({ id, message: 'PubReview видалено успішно.' });
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Internal Server Error' });
}
};
const updatePubReview = async (req, res) => {
try {
const id = req.params.id;
const updatedData = req.body;
const query = 'UPDATE PubReview SET ? WHERE id = ?';
await db.query(query, [updatedData, id]);
res.json({ id: id, ...updatedData });
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Internal Server Error' });
}
};
module.exports = {
getAllPubReview,
getPubReviewById,
createPubReview,
deletePubReview,
updatePubReview
};