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

fix more bugs

This commit is contained in:
Nikita Melnikov 2022-10-02 13:41:45 +08:00
parent a59ee3b413
commit 0a13064672
2 changed files with 9 additions and 9 deletions

View file

@ -1,4 +1,4 @@
import database, {isEntityId} from '../utils/database/index.js'; import database, {isEntityId, isEqualIds} from '../utils/database/index.js';
import { ObjectId } from 'mongodb'; import { ObjectId } from 'mongodb';
import { EntityId } from '../utils/database/types.js'; import { EntityId } from '../utils/database/types.js';
@ -147,7 +147,7 @@ class PageOrder {
return; return;
} }
const found = this.order.indexOf(pageId); const found = this.order.findIndex(order => isEqualIds(order, pageId));
if (found >= 0) { if (found >= 0) {
this.order.splice(found, 1); this.order.splice(found, 1);
@ -164,8 +164,8 @@ class PageOrder {
return; return;
} }
const found1 = this.order.indexOf(putAbovePageId); const found1 = this.order.findIndex(order => isEqualIds(order, putAbovePageId));
const found2 = this.order.indexOf(currentPageId); const found2 = this.order.findIndex(order => isEqualIds(order,currentPageId));
if (found1 === -1 || found2 === -1) { if (found1 === -1 || found2 === -1) {
return; return;
@ -187,7 +187,7 @@ class PageOrder {
return null; return null;
} }
const currentPageInOrder = this.order.indexOf(pageId); const currentPageInOrder = this.order.findIndex(order => isEqualIds(order, pageId));
/** /**
* If page not found or first return nothing * If page not found or first return nothing
@ -209,7 +209,7 @@ class PageOrder {
return null; return null;
} }
const currentPageInOrder = this.order.indexOf(pageId); const currentPageInOrder = this.order.findIndex(order => isEqualIds(order, pageId));
/** /**
* If page not found or is last * If page not found or is last

View file

@ -3,7 +3,7 @@ import multerFunc from 'multer';
import Pages from '../../controllers/pages.js'; import Pages from '../../controllers/pages.js';
import PagesOrder from '../../controllers/pagesOrder.js'; import PagesOrder from '../../controllers/pagesOrder.js';
import { EntityId } from '../../utils/database/types.js'; import { EntityId } from '../../utils/database/types.js';
import {isEntityId, toEntityId} from "../../utils/database/index.js"; import {isEntityId, isEqualIds, toEntityId} from "../../utils/database/index.js";
const router = express.Router(); const router = express.Router();
const multer = multerFunc(); const multer = multerFunc();
@ -105,11 +105,11 @@ router.post('/page/:id', multer.none(), async (req: Request, res: Response) => {
throw new Error('Parent not found'); throw new Error('Parent not found');
} }
if (page._parent !== parent) { if (!isEqualIds(page._parent, parent)) {
await PagesOrder.move(page._parent, parent, id); await PagesOrder.move(page._parent, parent, id);
} else { } else {
if (putAbovePageId && putAbovePageId !== '0') { if (putAbovePageId && putAbovePageId !== '0') {
const unordered = pages.filter(_page => _page._parent === page._parent).map(_page => _page._id); const unordered = pages.filter(_page => isEqualIds(_page._parent, page._parent)).map(_page => _page._id);
const unOrdered: EntityId[] = []; const unOrdered: EntityId[] = [];