From f4b35778012cd210b0ac37965156742b5a93a8fc Mon Sep 17 00:00:00 2001 From: Nikita Melnikov Date: Mon, 3 Oct 2022 20:16:35 +0800 Subject: [PATCH] fix sorting --- src/backend/database/index.ts | 4 ++++ src/backend/routes/api/pages.ts | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/backend/database/index.ts b/src/backend/database/index.ts index 2e188e6..7f0bb18 100644 --- a/src/backend/database/index.ts +++ b/src/backend/database/index.ts @@ -16,6 +16,10 @@ const Database = appConfig.database.driver === 'mongodb' ? MongoDatabaseDriver : * @param id - id to convert */ export function toEntityId(id: string): EntityId { + if (id === '0') { + return id as EntityId; + } + return (appConfig.database.driver === 'mongodb' ? new ObjectId(id) : id) as EntityId; } diff --git a/src/backend/routes/api/pages.ts b/src/backend/routes/api/pages.ts index a64596b..759efbd 100644 --- a/src/backend/routes/api/pages.ts +++ b/src/backend/routes/api/pages.ts @@ -58,7 +58,8 @@ router.get('/pages', async (req: Request, res: Response) => { */ router.put('/page', multer.none(), async (req: Request, res: Response) => { try { - const { title, body, parent } = req.body; + const { title, body } = req.body; + const parent = toEntityId(req.body.parent); const page = await Pages.insert({ title, body,