1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-08 06:55:26 +02:00

push migration

This commit is contained in:
Murod Khaydarov 2019-02-18 14:54:31 +03:00
parent c7fe843651
commit 4fc37e42b5
No known key found for this signature in database
GPG key ID: C480BA53A8D274C5
2 changed files with 26 additions and 6 deletions

View file

@ -167,6 +167,13 @@ class PageOrder {
return this.order[currentPageInOrder + 1];
}
/**
* @param {string[]} order - define new order
*/
set order(order) {
this._order = order
}
/**
* Returns ordered list
*

View file

@ -1,6 +1,5 @@
const Datastore = require('nedb');
const config = require('../../../config');
const db = new Datastore({filename: `./${config.database}/pagesOrder.db`, autoload: true});
/**
@ -22,11 +21,25 @@ const db = new Datastore({filename: `./${config.database}/pagesOrder.db`, autolo
});
if (!order) {
const initialData = {
page: '0',
order: []
};
await db.insert(initialData);
const Pages = require('../../controllers/pages');
// Converter
const pages = await Pages.getAll();
async function convert(pages, parentId) {
const children = pages.filter(page => page._parent === parentId);
const initialData = {
page: parentId,
order: children.map(page => page._id)
};
await db.insert(initialData);
children.forEach(async page => {
await convert(pages, page._id);
});
}
await convert(pages, parentIdOfRootPages);
}
}());