mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 02:56:41 +07:00
24 lines
809 B
JavaScript
24 lines
809 B
JavaScript
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, 64);
|
|
const is_public = !!body.is_public;
|
|
|
|
const exists = await Route.findOne({ _id: address, is_deleted: false }).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' });
|
|
|
|
await exists.set({ title, is_public }).save();
|
|
|
|
return res.send({ success: true, ...exists });
|
|
};
|
|
|