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:
parent
529aca5e29
commit
7890d17255
5 changed files with 79 additions and 65 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue