mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-08 06:55:26 +02:00
fix eslint
This commit is contained in:
parent
a5bae002a5
commit
0c83be638b
7 changed files with 29 additions and 13 deletions
|
@ -1,11 +1,11 @@
|
|||
import Page, {PageData} from '../models/page.js';
|
||||
import Page, { PageData } from '../models/page.js';
|
||||
import Alias from '../models/alias.js';
|
||||
import PagesOrder from './pagesOrder.js';
|
||||
import PageOrder from '../models/pageOrder.js';
|
||||
import HttpException from '../exceptions/httpException.js';
|
||||
import PagesFlatArray from '../models/pagesFlatArray.js';
|
||||
import {EntityId} from '../utils/database/types.js';
|
||||
import {isEqualIds} from "../utils/database/index.js";
|
||||
import { EntityId } from '../utils/database/types.js';
|
||||
import { isEqualIds } from '../utils/database/index.js';
|
||||
|
||||
type PageDataFields = keyof PageData;
|
||||
|
||||
|
@ -68,6 +68,9 @@ class Pages {
|
|||
return nullFilteredPages;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static async getPagesMap(): Promise<Map<string, Page>> {
|
||||
const pages = await Pages.getAllPages();
|
||||
const pagesMap = new Map<string, Page>();
|
||||
|
@ -106,18 +109,22 @@ class Pages {
|
|||
|
||||
const getChildrenOrder = (pageId: EntityId): EntityId[] => {
|
||||
const order = childPageOrder.find((order) => isEqualIds(order.page, pageId))?.order || [];
|
||||
|
||||
if (order.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const expandedOrder = order.map((id) => [id,...getChildrenOrder(id)]);
|
||||
const expandedOrder = order.map((id) => [id, ...getChildrenOrder(id)]);
|
||||
|
||||
return expandedOrder.flat();
|
||||
}
|
||||
};
|
||||
|
||||
const orderGroupedByParent = idsOfRootPages.reduce((acc, curr) => {
|
||||
const pageOrder = getChildrenOrder(curr);
|
||||
|
||||
acc[curr.toString()] = [curr, ...pageOrder];
|
||||
|
||||
return acc;
|
||||
}, {} as Record<string, EntityId[]>)
|
||||
}, {} as Record<string, EntityId[]>);
|
||||
|
||||
/**
|
||||
* It converts grouped pages(object) to array
|
||||
|
|
|
@ -2,7 +2,7 @@ import PageOrder from '../models/pageOrder.js';
|
|||
import Page from '../models/page.js';
|
||||
import PagesFlatArray from '../models/pagesFlatArray.js';
|
||||
import { EntityId } from '../utils/database/types.js';
|
||||
import {isEqualIds} from "../utils/database/index.js";
|
||||
import { isEqualIds } from '../utils/database/index.js';
|
||||
|
||||
/**
|
||||
* @class PagesOrder
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import database, {isEntityId, isEqualIds} from '../utils/database/index.js';
|
||||
import database, { isEntityId, isEqualIds } from '../utils/database/index.js';
|
||||
import { ObjectId } from 'mongodb';
|
||||
import { EntityId } from '../utils/database/types.js';
|
||||
|
||||
|
@ -165,7 +165,7 @@ class PageOrder {
|
|||
}
|
||||
|
||||
const found1 = this.order.findIndex(order => isEqualIds(order, putAbovePageId));
|
||||
const found2 = this.order.findIndex(order => isEqualIds(order,currentPageId));
|
||||
const found2 = this.order.findIndex(order => isEqualIds(order, currentPageId));
|
||||
|
||||
if (found1 === -1 || found2 === -1) {
|
||||
return;
|
||||
|
|
|
@ -3,7 +3,7 @@ import multerFunc from 'multer';
|
|||
import Pages from '../../controllers/pages.js';
|
||||
import PagesOrder from '../../controllers/pagesOrder.js';
|
||||
import { EntityId } from '../../utils/database/types.js';
|
||||
import {isEntityId, isEqualIds, toEntityId} from "../../utils/database/index.js";
|
||||
import { isEntityId, isEqualIds, toEntityId } from '../../utils/database/index.js';
|
||||
|
||||
const router = express.Router();
|
||||
const multer = multerFunc();
|
||||
|
@ -202,7 +202,7 @@ router.delete('/page/:id', async (req: Request, res: Response) => {
|
|||
}
|
||||
};
|
||||
|
||||
const id = toEntityId(req.params.id)
|
||||
const id = toEntityId(req.params.id);
|
||||
|
||||
await deleteRecursively(id);
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import Page from '../../models/page.js';
|
|||
import asyncMiddleware from '../../utils/asyncMiddleware.js';
|
||||
import PageOrder from '../../models/pageOrder.js';
|
||||
import { EntityId } from '../../utils/database/types.js';
|
||||
import {isEqualIds} from "../../utils/database/index.js";
|
||||
import { isEqualIds } from '../../utils/database/index.js';
|
||||
|
||||
/**
|
||||
* Process one-level pages list to parent-children list
|
||||
|
|
|
@ -18,10 +18,19 @@ export function toEntityId(id: string): EntityId {
|
|||
return (appConfig.database.driver === 'mongodb' ? new ObjectId(id) : id) as EntityId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id1
|
||||
* @param id2
|
||||
*/
|
||||
export function isEqualIds(id1?: EntityId, id2?: EntityId): boolean {
|
||||
return id1?.toString() === id2?.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
export function isEntityId(id?: EntityId): id is EntityId {
|
||||
return typeof id === 'string' || id instanceof ObjectId;
|
||||
}
|
||||
|
|
|
@ -57,5 +57,5 @@ export default (function () {
|
|||
|
||||
twig.extendFilter('json_stringify', function (data: any): string {
|
||||
return JSON.stringify(data);
|
||||
})
|
||||
});
|
||||
}());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue