mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
feat: get documents api route with pagination
This commit is contained in:
21
packages/lib/server-only/public-api/get-documents.ts
Normal file
21
packages/lib/server-only/public-api/get-documents.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
type GetDocumentsProps = {
|
||||
page: number;
|
||||
perPage: number;
|
||||
};
|
||||
|
||||
export const getDocuments = async ({ page = 1, perPage = 10 }: GetDocumentsProps) => {
|
||||
const [documents, count] = await Promise.all([
|
||||
await prisma.document.findMany({
|
||||
take: perPage,
|
||||
skip: Math.max(page - 1, 0) * perPage,
|
||||
}),
|
||||
await prisma.document.count(),
|
||||
]);
|
||||
|
||||
return {
|
||||
documents,
|
||||
totalPages: Math.ceil(count / perPage),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user