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 { parseQuery } from '@/lib/api/route-helpers';
|
|
|
|
|
import { errorResponse } from '@/lib/errors';
|
2026-05-11 12:06:49 +02:00
|
|
|
import { listFiles, listFilesAggregatedByEntity } from '@/lib/services/files';
|
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 { listFilesSchema } from '@/lib/validators/files';
|
|
|
|
|
|
|
|
|
|
export const GET = withAuth(
|
|
|
|
|
withPermission('files', 'view', async (req, ctx) => {
|
|
|
|
|
try {
|
|
|
|
|
const query = parseQuery(req, listFilesSchema);
|
2026-05-11 12:06:49 +02:00
|
|
|
|
|
|
|
|
if (query.entityType && query.entityId) {
|
|
|
|
|
const result = await listFilesAggregatedByEntity(
|
|
|
|
|
ctx.portId,
|
|
|
|
|
query.entityType,
|
|
|
|
|
query.entityId,
|
|
|
|
|
);
|
|
|
|
|
return NextResponse.json({ data: result });
|
|
|
|
|
}
|
|
|
|
|
|
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 result = await listFiles(ctx.portId, query);
|
|
|
|
|
|
|
|
|
|
const { page, limit } = query;
|
|
|
|
|
const totalPages = Math.ceil(result.total / limit);
|
|
|
|
|
|
|
|
|
|
return NextResponse.json({
|
|
|
|
|
data: result.data,
|
|
|
|
|
pagination: {
|
|
|
|
|
page,
|
|
|
|
|
pageSize: limit,
|
|
|
|
|
total: result.total,
|
|
|
|
|
totalPages,
|
|
|
|
|
hasNextPage: page < totalPages,
|
|
|
|
|
hasPreviousPage: page > 1,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return errorResponse(error);
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
);
|