feat: Add parentDocumentId option to documents.list endpoint

This commit is contained in:
Tom Moor
2019-12-22 17:06:29 -08:00
parent 6bf2069fa7
commit d995f27736
2 changed files with 12 additions and 2 deletions

View File

@ -30,10 +30,9 @@ const { authorize, cannot } = policy;
const router = new Router(); const router = new Router();
router.post('documents.list', auth(), pagination(), async ctx => { 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 collectionId = ctx.body.collection;
const createdById = ctx.body.user; const createdById = ctx.body.user;
const backlinkDocumentId = ctx.body.backlinkDocumentId;
let direction = ctx.body.direction; let direction = ctx.body.direction;
if (direction !== 'ASC') direction = 'DESC'; if (direction !== 'ASC') direction = 'DESC';
@ -64,7 +63,14 @@ router.post('documents.list', auth(), pagination(), async ctx => {
where = { ...where, collectionId: collectionIds }; where = { ...where, collectionId: collectionIds };
} }
if (parentDocumentId) {
ctx.assertUuid(parentDocumentId, 'parentDocumentId must be a UUID');
where = { ...where, parentDocumentId };
}
if (backlinkDocumentId) { if (backlinkDocumentId) {
ctx.assertUuid(backlinkDocumentId, 'backlinkDocumentId must be a UUID');
const backlinks = await Backlink.findAll({ const backlinks = await Backlink.findAll({
attributes: ['reverseDocumentId'], attributes: ['reverseDocumentId'],
where: { where: {

View File

@ -269,6 +269,10 @@ export default function Api() {
id="backlinkDocumentId" id="backlinkDocumentId"
description="Backlinked document ID to filter by" description="Backlinked document ID to filter by"
/> />
<Argument
id="parentDocumentId"
description="Parent document ID to filter by"
/>
</Arguments> </Arguments>
</Method> </Method>