From d995f27736eee45aaa5dcea262acb7b3dc0a2bdc Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 22 Dec 2019 17:06:29 -0800 Subject: [PATCH] feat: Add parentDocumentId option to documents.list endpoint --- server/api/documents.js | 10 ++++++++-- server/pages/developers/Api.js | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/server/api/documents.js b/server/api/documents.js index 05fe33db..d1d1d3f0 100644 --- a/server/api/documents.js +++ b/server/api/documents.js @@ -30,10 +30,9 @@ const { authorize, cannot } = policy; const router = new Router(); router.post('documents.list', auth(), pagination(), async ctx => { - const { sort = 'updatedAt' } = ctx.body; + const { sort = 'updatedAt', backlinkDocumentId, parentDocumentId } = ctx.body; const collectionId = ctx.body.collection; const createdById = ctx.body.user; - const backlinkDocumentId = ctx.body.backlinkDocumentId; let direction = ctx.body.direction; if (direction !== 'ASC') direction = 'DESC'; @@ -64,7 +63,14 @@ router.post('documents.list', auth(), pagination(), async ctx => { where = { ...where, collectionId: collectionIds }; } + if (parentDocumentId) { + ctx.assertUuid(parentDocumentId, 'parentDocumentId must be a UUID'); + where = { ...where, parentDocumentId }; + } + if (backlinkDocumentId) { + ctx.assertUuid(backlinkDocumentId, 'backlinkDocumentId must be a UUID'); + const backlinks = await Backlink.findAll({ attributes: ['reverseDocumentId'], where: { diff --git a/server/pages/developers/Api.js b/server/pages/developers/Api.js index 6ad68767..8a61a419 100644 --- a/server/pages/developers/Api.js +++ b/server/pages/developers/Api.js @@ -269,6 +269,10 @@ export default function Api() { id="backlinkDocumentId" description="Backlinked document ID to filter by" /> +