Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
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,
|
2026-04-28 02:39:46 +02:00
|
|
|
getDocumentDetail,
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
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 {
|
2026-04-28 02:39:46 +02:00
|
|
|
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 });
|
|
|
|
|
}
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
);
|