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" /> +