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
|
@ -4,9 +4,11 @@ const get = require('./route/get');
|
|||
const list = require('./route/list');
|
||||
const drop = require('./route/drop');
|
||||
const patch = require('./route/patch');
|
||||
const star = require('./route/star');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/star', star);
|
||||
router.post('/', post);
|
||||
router.get('/', get);
|
||||
router.patch('/', patch);
|
||||
|
|
|
@ -3,10 +3,12 @@ const { Route, User } = require('../../models');
|
|||
module.exports = async (req, res) => {
|
||||
const {
|
||||
query: {
|
||||
id, token, title, distance, author, step = 20, shift = 0,
|
||||
id, token, title, distance, author, step = 20, shift = 0, starred,
|
||||
}
|
||||
} = req;
|
||||
|
||||
const is_starred = parseInt(starred, 10) === 1;
|
||||
|
||||
const user = await User.findOne({ _id: id, token });
|
||||
|
||||
let criteria = { is_deleted: false };
|
||||
|
@ -14,13 +16,21 @@ module.exports = async (req, res) => {
|
|||
if (title) {
|
||||
criteria = {
|
||||
...criteria,
|
||||
$or: [
|
||||
$and: [
|
||||
{ title: new RegExp(title.trim(), 'ig') },
|
||||
{ _id: new RegExp(title.trim(), 'ig') },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
console.log('is starred?', starred);
|
||||
if (is_starred) {
|
||||
criteria = {
|
||||
...criteria,
|
||||
is_starred: true,
|
||||
};
|
||||
}
|
||||
|
||||
if (!author || !user || (user._id !== author)) {
|
||||
criteria = {
|
||||
...criteria,
|
||||
|
@ -32,7 +42,7 @@ module.exports = async (req, res) => {
|
|||
{
|
||||
...criteria,
|
||||
},
|
||||
'_id title distance owner updated_at is_public is_deleted',
|
||||
'_id title distance owner updated_at is_public is_deleted is_starred',
|
||||
{
|
||||
limit: 9000,
|
||||
sort: { updated_at: -1 },
|
||||
|
|
|
@ -17,7 +17,7 @@ module.exports = async (req, res) => {
|
|||
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();
|
||||
await exists.set({ title, is_public }).save();
|
||||
|
||||
return res.send({ success: true, ...exists });
|
||||
};
|
||||
|
|
|
@ -27,7 +27,7 @@ module.exports = async (req, res) => {
|
|||
if (exists && !force) return res.send({ success: false, mode: 'overwriting' });
|
||||
|
||||
if (exists) {
|
||||
exists.set({
|
||||
await exists.set({
|
||||
title, route, stickers, logo, distance, updated_at: Date.now(), provider, is_public,
|
||||
}).save();
|
||||
|
||||
|
|
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