Files
pn-new-crm/src/app/api/v1/documents/[id]/route.ts
Matt Ciaccio aa15807063 feat(documents): detail page with signers, watchers, activity, actions
Replaces the PR4 stub at /documents/[id] with the full Phase A detail
view: gradient header strip, status-aware action bar (Cancel /
Download / Email signatories), per-signer remind + copy-link, watcher
list with remove, and activity timeline. Adds the supporting endpoints
(cancel, compose-completion-email, watchers GET/POST/DELETE) and
listDocumentWatchers / addDocumentWatcher / removeDocumentWatcher
service helpers. The document GET now serves the aggregator shape
when ?detail=true.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 02:39:46 +02:00

62 lines
1.8 KiB
TypeScript

import { NextResponse } from 'next/server';
import { withAuth, withPermission } from '@/lib/api/helpers';
import { parseBody } from '@/lib/api/route-helpers';
import { errorResponse } from '@/lib/errors';
import {
getDocumentById,
getDocumentDetail,
updateDocument,
deleteDocument,
} from '@/lib/services/documents.service';
import { updateDocumentSchema } from '@/lib/validators/documents';
export const GET = withAuth(
withPermission('documents', 'view', async (req, ctx, params) => {
try {
const url = new URL(req.url);
if (url.searchParams.get('detail') === 'true') {
const detail = await getDocumentDetail(params.id!, ctx.portId);
return NextResponse.json({ data: detail });
}
const doc = await getDocumentById(params.id!, ctx.portId);
return NextResponse.json({ data: doc });
} catch (error) {
return errorResponse(error);
}
}),
);
export const PATCH = withAuth(
withPermission('documents', 'edit', async (req, ctx, params) => {
try {
const body = await parseBody(req, updateDocumentSchema);
const doc = await updateDocument(params.id!, ctx.portId, body, {
userId: ctx.userId,
portId: ctx.portId,
ipAddress: ctx.ipAddress,
userAgent: ctx.userAgent,
});
return NextResponse.json({ data: doc });
} catch (error) {
return errorResponse(error);
}
}),
);
export const DELETE = withAuth(
withPermission('documents', 'delete', async (req, ctx, params) => {
try {
await deleteDocument(params.id!, ctx.portId, {
userId: ctx.userId,
portId: ctx.portId,
ipAddress: ctx.ipAddress,
userAgent: ctx.userAgent,
});
return new NextResponse(null, { status: 204 });
} catch (error) {
return errorResponse(error);
}
}),
);