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

fix: fix order of page categories with raw type

This commit is contained in:
Y-k-Y 2022-04-28 02:21:10 +09:00
parent f75401d0fb
commit 76f05fe274

View file

@ -84,9 +84,45 @@ class Page {
* @returns {Promise<Page[]>}
*/
public static async getAll(query: Record<string, unknown> = {}): Promise<Page[]> {
const docs = await pagesDb.find(query);
const result: PageData[] = [];
const obj = {};
let docs = await pagesDb.find(query);
return Promise.all(docs.map(doc => new Page(doc)));
docs = docs.sort((a, b) => {
if (a.body.time > b.body.time) {
return 1;
}
if (a.body.time < b.body.time) {
return -1;
}
return 0;
});
docs.forEach(doc => {
if(doc.parent === '0') {
// @ts-ignore
obj[doc._id] = [];
// @ts-ignore
obj[doc._id].push(doc);
} else {
// @ts-ignore
obj[doc._id] = [];
// @ts-ignore
obj[doc.parent].push(doc);
}
});
Object.entries(obj).forEach(([key, value]) => {
// @ts-ignore
if(!key || value.length <=0) {
return;
} else {
// @ts-ignore
result.push(...value);
}
});
return Promise.all(result.map(doc => new Page(doc)));
}
/**