mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 11:06:40 +07:00
backend: drop and modify
This commit is contained in:
parent
17a929956c
commit
7513f79b93
7 changed files with 81 additions and 2 deletions
24
backend/routes/route/patch.js
Normal file
24
backend/routes/route/patch.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
const { User, Route } = require('../../models');
|
||||
|
||||
const { parseString } = require('../../utils/parse');
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const { body, body: { id, token, address } } = req;
|
||||
|
||||
const owner = await User.findOne({ _id: id, token }).populate('routes');
|
||||
|
||||
if (!owner) return res.send({ success: false, reason: 'unauthorized' });
|
||||
|
||||
const title = parseString(body.title, 32);
|
||||
const is_public = !!body.is_public;
|
||||
|
||||
const exists = await Route.findOne({ _id: address }).populate('owner', '_id');
|
||||
|
||||
if (!exists) return res.send({ success: false, mode: 'not_exists' });
|
||||
if (exists && exists.owner._id !== id) return res.send({ success: false, mode: 'not_yours' });
|
||||
|
||||
exists.set({ title, is_public }).save();
|
||||
|
||||
return res.send({ success: true, ...exists });
|
||||
};
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue