feat: Add parentDocumentId option to documents.list endpoint
This commit is contained in:
@ -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: {
|
||||||
|
@ -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>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user