feat(documents): entity-aggregated query params + signing-details API
GET /api/v1/files?entityType=client&entityId=… and the same params on
the documents route return the owner-aggregated projection
{ groups: [{ label, source, files|workflows, total }] }. folderId
remains for direct-folder listing; the two modes are mutually
exclusive (zod refine).
GET /api/v1/documents/[id]/signing-details returns
{ workflow, signers, events } for the "view signing details" dialog
on signed-PDF rows.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
25
src/app/api/v1/documents/[id]/signing-details/route.ts
Normal file
25
src/app/api/v1/documents/[id]/signing-details/route.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import { withAuth, withPermission } from '@/lib/api/helpers';
|
||||
import { errorResponse } from '@/lib/errors';
|
||||
import {
|
||||
getDocumentById,
|
||||
listDocumentSigners,
|
||||
listDocumentEvents,
|
||||
} from '@/lib/services/documents.service';
|
||||
|
||||
export const GET = withAuth(
|
||||
withPermission('documents', 'view', async (_req, ctx, params) => {
|
||||
try {
|
||||
const id = params.id!;
|
||||
const [workflow, signers, events] = await Promise.all([
|
||||
getDocumentById(id, ctx.portId),
|
||||
listDocumentSigners(id, ctx.portId),
|
||||
listDocumentEvents(id, ctx.portId),
|
||||
]);
|
||||
return NextResponse.json({ data: { workflow, signers, events } });
|
||||
} catch (error) {
|
||||
return errorResponse(error);
|
||||
}
|
||||
}),
|
||||
);
|
||||
@@ -3,13 +3,27 @@ import { NextResponse } from 'next/server';
|
||||
import { withAuth, withPermission } from '@/lib/api/helpers';
|
||||
import { parseQuery, parseBody } from '@/lib/api/route-helpers';
|
||||
import { errorResponse } from '@/lib/errors';
|
||||
import { listDocuments, createDocument } from '@/lib/services/documents.service';
|
||||
import {
|
||||
listDocuments,
|
||||
createDocument,
|
||||
listInflightWorkflowsAggregatedByEntity,
|
||||
} from '@/lib/services/documents.service';
|
||||
import { listDocumentsSchema, createDocumentSchema } from '@/lib/validators/documents';
|
||||
|
||||
export const GET = withAuth(
|
||||
withPermission('documents', 'view', async (req, ctx) => {
|
||||
try {
|
||||
const query = parseQuery(req, listDocumentsSchema);
|
||||
|
||||
if (query.entityType && query.entityId) {
|
||||
const result = await listInflightWorkflowsAggregatedByEntity(
|
||||
ctx.portId,
|
||||
query.entityType,
|
||||
query.entityId,
|
||||
);
|
||||
return NextResponse.json({ data: result });
|
||||
}
|
||||
|
||||
const result = await listDocuments(ctx.portId, query, {
|
||||
currentUserEmail: ctx.user.email,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user