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
19
backend/routes/route/drop.js
Normal file
19
backend/routes/route/drop.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
const { User, Route } = require('../../models');
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const { 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 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.delete();
|
||||
|
||||
return res.send({ success: true, address });
|
||||
};
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue