Files
pn-new-crm/src/app/api/v1/files/route.ts

34 lines
969 B
TypeScript
Raw Normal View History

import { NextResponse } from 'next/server';
import { withAuth, withPermission } from '@/lib/api/helpers';
import { parseQuery } from '@/lib/api/route-helpers';
import { errorResponse } from '@/lib/errors';
import { listFiles } from '@/lib/services/files';
import { listFilesSchema } from '@/lib/validators/files';
export const GET = withAuth(
withPermission('files', 'view', async (req, ctx) => {
try {
const query = parseQuery(req, listFilesSchema);
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);
}
}),
);