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

refactor createMenuTree (#44)

* refactor createmenutree

* Update src/routes/middlewares/pages.js

Co-Authored-By: khaydarov <murod.haydarov@inbox.ru>

* push migration

* update

* remove migration and order is optional

* eslint fixes
This commit is contained in:
Murod Khaydarov 2019-02-19 17:29:45 +03:00 committed by GitHub
parent 529aca5e29
commit 7890d17255
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 65 deletions

View file

@ -1,34 +1,5 @@
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;