1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-07-19 13:19:42 +02:00

Order child pages (#21)

* save ordering pages

* move to another collection

* requested changes. Code improvements

* add margin

* unit tests

* fix

* requested changes

* recursive method: create menu tree

* update comments

* fix bug

* requested changes

* move const

* fix error message on catch

* add migration

* rewrite to splices

* move methods

* testing put above method

* linter fix
This commit is contained in:
Murod Khaydarov 2019-01-19 17:09:11 +03:00 committed by GitHub
parent dbfc594e66
commit d61818761e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 1069 additions and 2563 deletions

View file

@ -2,6 +2,7 @@ const express = require('express');
const router = express.Router();
const multer = require('multer')();
const Pages = require('../../controllers/pages');
const PagesOrder = require('../../controllers/pagesOrder');
/**
* GET /page/:id
@ -55,6 +56,9 @@ router.put('/page', multer.any(), async (req, res) => {
const {title, body, parent} = req.body;
const page = await Pages.insert({title, body, parent});
/** push to the orders array */
await PagesOrder.push(parent, page._id);
res.json({
success: true,
result: page
@ -76,9 +80,18 @@ router.post('/page/:id', multer.any(), async (req, res) => {
const {id} = req.params;
try {
const {title, body, parent} = req.body;
const page = await Pages.update(id, {title, body, parent});
const {title, body, parent, putAbovePageId} = req.body;
let page = await Pages.get(id);
if (page._parent !== parent) {
await PagesOrder.move(page._parent, parent, id);
} else {
if (putAbovePageId && putAbovePageId !== '0') {
await PagesOrder.update(page._id, page._parent, putAbovePageId);
}
}
page = await Pages.update(id, {title, body, parent});
res.json({
success: true,
result: page