mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-05-03 06:56:41 +07:00
starred content
This commit is contained in:
parent
a920217959
commit
baa41f707d
19 changed files with 159 additions and 22 deletions
backend/routes/route
|
@ -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 },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue