Files
sign/packages/lib/server-only/template/get-templates.ts

36 lines
705 B
TypeScript
Raw Normal View History

2023-10-06 22:54:24 +00:00
import { prisma } from '@documenso/prisma';
export type GetTemplatesOptions = {
userId: number;
page: number;
perPage: number;
};
export const getTemplates = async ({ userId, page = 1, perPage = 10 }: GetTemplatesOptions) => {
const [templates, count] = await Promise.all([
2023-12-21 17:36:35 +11:00
prisma.template.findMany({
2023-10-06 22:54:24 +00:00
where: {
userId,
},
include: {
templateDocumentData: true,
Field: true,
},
skip: Math.max(page - 1, 0) * perPage,
orderBy: {
createdAt: 'desc',
},
}),
2023-12-21 17:36:35 +11:00
prisma.template.count({
2023-10-06 22:54:24 +00:00
where: {
2023-12-21 17:36:35 +11:00
userId,
2023-10-06 22:54:24 +00:00
},
}),
]);
return {
templates,
totalPages: Math.ceil(count / perPage),
};
};