mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
26 lines
544 B
TypeScript
26 lines
544 B
TypeScript
import { prisma } from '@documenso/prisma';
|
|
|
|
type GetDocumentsProps = {
|
|
page: number;
|
|
perPage: number;
|
|
userId: number;
|
|
};
|
|
|
|
export const getDocuments = async ({ page = 1, perPage = 10, userId }: GetDocumentsProps) => {
|
|
const [documents, count] = await Promise.all([
|
|
await prisma.document.findMany({
|
|
where: {
|
|
userId,
|
|
},
|
|
take: perPage,
|
|
skip: Math.max(page - 1, 0) * perPage,
|
|
}),
|
|
await prisma.document.count(),
|
|
]);
|
|
|
|
return {
|
|
documents,
|
|
totalPages: Math.ceil(count / perPage),
|
|
};
|
|
};
|