-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstarRoutes.js
More file actions
33 lines (29 loc) · 803 Bytes
/
starRoutes.js
File metadata and controls
33 lines (29 loc) · 803 Bytes
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
const {showStars} = require('../services/stars/showStars');
const {updateChanges} = require('../services/stars/updateStar');
module.exports = (app) => {
app.use("/api/star", (req, res, next) => {
if (!req.user) {
res.send({error: 'No user'});
} else {
next();
}
});
app.put('/api/star/updateChanges', async (req, res) => {
const userId = req.user.id;
const changes = req.body.changes;
try {
const result = await updateChanges(userId, changes);
res.send(result);
} catch (error) {
console.error(error);
res.send({
error: {message: error.message}
});
}
});
app.get('/api/star/get', async (req, res) => {
const userId = req.user.id;
const stuff = await showStars(userId);
res.send(stuff);
});
};