mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 02:56:41 +07:00
complete setting and editing description
This commit is contained in:
parent
c040e33a8a
commit
8f60a5efd6
10 changed files with 118 additions and 91 deletions
|
@ -2,24 +2,22 @@ const mongoose = require('mongoose');
|
|||
|
||||
const { Schema } = mongoose;
|
||||
|
||||
const RouteSchema = new Schema(
|
||||
{
|
||||
_id: { type: String, required: true },
|
||||
title: { type: String, default: '' },
|
||||
// address: { type: String, required: true },
|
||||
version: { type: Number, default: 2 },
|
||||
route: { type: Array, default: [] },
|
||||
stickers: { type: Array, default: [] },
|
||||
owner: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
distance: { type: Number, default: 0 },
|
||||
is_public: { type: Boolean, default: false },
|
||||
is_starred: { type: Boolean, default: false },
|
||||
is_deleted: { type: Boolean, default: false },
|
||||
created_at: { type: Date, default: Date.now() },
|
||||
updated_at: { type: Date, default: Date.now() },
|
||||
logo: { type: String, default: 'DEFAULT' },
|
||||
provider: { type: String, default: 'DEFAULT' },
|
||||
},
|
||||
);
|
||||
const RouteSchema = new Schema({
|
||||
_id: { type: String, required: true },
|
||||
title: { type: String, default: '' },
|
||||
version: { type: Number, default: 2 },
|
||||
route: { type: Array, default: [] },
|
||||
stickers: { type: Array, default: [] },
|
||||
owner: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
distance: { type: Number, default: 0 },
|
||||
is_public: { type: Boolean, default: false },
|
||||
is_starred: { type: Boolean, default: false },
|
||||
is_deleted: { type: Boolean, default: false },
|
||||
created_at: { type: Date, default: Date.now() },
|
||||
updated_at: { type: Date, default: Date.now() },
|
||||
logo: { type: String, default: 'DEFAULT' },
|
||||
provider: { type: String, default: 'DEFAULT' },
|
||||
description: { type: String, default: '' },
|
||||
});
|
||||
|
||||
module.exports.RouteSchema = RouteSchema;
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
const { User, Route } = require('../../models');
|
||||
|
||||
const { parseRoute, parseStickers, parseString, parseNumber, parseAddress } = require('../../utils/parse');
|
||||
const {
|
||||
parseRoute, parseStickers, parseString, parseNumber, parseAddress
|
||||
} = require('../../utils/parse');
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const { body, body: { id, token, force } } = req;
|
||||
|
||||
const owner = await User.findOne({ _id: id, token }).populate('routes');
|
||||
if (!owner) return res.send({ success: false, reason: 'unauthorized', id, token });
|
||||
if (!owner) {
|
||||
return res.send({
|
||||
success: false, reason: 'unauthorized', id, token
|
||||
});
|
||||
}
|
||||
|
||||
const title = parseString(body.title, 64);
|
||||
const description = parseString(body.description, 256);
|
||||
const address = parseAddress(body.address, 32);
|
||||
const route = parseRoute(body.route);
|
||||
const stickers = parseStickers(body.stickers);
|
||||
|
@ -28,23 +35,23 @@ module.exports = async (req, res) => {
|
|||
|
||||
if (exists) {
|
||||
await exists.set({
|
||||
title, route, stickers, logo, distance, updated_at: Date.now(), provider, is_public,
|
||||
title, route, stickers, logo, distance, updated_at: Date.now(), provider, is_public, description,
|
||||
}).save();
|
||||
|
||||
return res.send({
|
||||
success: true, title, address, route, stickers, mode: 'overwrited', is_public,
|
||||
success: true, title, address, route, stickers, mode: 'overwrited', is_public, description,
|
||||
});
|
||||
}
|
||||
|
||||
const created = await Route.create({
|
||||
_id: address, title, route, stickers, owner, logo, distance, provider, is_public,
|
||||
_id: address, title, route, stickers, owner, logo, distance, provider, is_public, description,
|
||||
});
|
||||
|
||||
await owner.routes.push(created);
|
||||
await owner.save();
|
||||
|
||||
return res.send({
|
||||
success: true, title, address, route, stickers, provider, is_public,
|
||||
success: true, title, address, route, stickers, provider, is_public, description,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue