1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-07-22 14:49:41 +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

@ -0,0 +1,34 @@
const Datastore = require('nedb');
const config = require('../../../config');
const db = new Datastore({filename: `./${config.database}/pagesOrder.db`, autoload: true});
/**
* Current DataStore preparation
* Add initial row for RootPage
*/
(async function() {
const parentIdOfRootPages = '0';
const cbk = (resolve, reject) => (err, doc) => {
if (err) {
reject(err);
}
resolve(doc);
};
const order = await new Promise((resolve, reject) => {
db.findOne({page: parentIdOfRootPages}, cbk(resolve, reject));
});
if (!order) {
const initialData = {
page: '0',
order: []
};
await db.insert(initialData);
}
}());
module.exports = db;