mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 11:06:40 +07:00
starred content
This commit is contained in:
parent
a920217959
commit
baa41f707d
19 changed files with 159 additions and 22 deletions
19
backend/routes/route/star.js
Normal file
19
backend/routes/route/star.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
const { User, Route } = require('../../models');
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const { body, body: { id, token, address } } = req;
|
||||
|
||||
const owner = await User.findOne({ _id: id, token }).populate('routes');
|
||||
|
||||
if (!owner || owner.role !== 'admin') return res.send({ success: false, reason: 'unauthorized' });
|
||||
|
||||
const is_starred = !!body.is_starred;
|
||||
|
||||
const exists = await Route.findOne({ _id: address }).populate('owner', '_id');
|
||||
if (!exists) return res.send({ success: false, mode: 'not_exists' });
|
||||
|
||||
await exists.set({ is_starred }).save();
|
||||
|
||||
return res.send({ success: true, ...exists });
|
||||
};
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue