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:
parent
f75401d0fb
commit
76f05fe274
1 changed files with 38 additions and 2 deletions
|
@ -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)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue