Files
documenso/packages/lib/server-only/template/get-template-by-id.ts
Adithya Krishna cce0cdfbe2 feat: add template meta for templates
Signed-off-by: Adithya Krishna <aadithya794@gmail.com>
2024-04-18 17:47:50 +05:30

36 lines
684 B
TypeScript

import { prisma } from '@documenso/prisma';
import type { Prisma } from '@documenso/prisma/client';
export interface GetTemplateByIdOptions {
id: number;
userId: number;
}
export const getTemplateById = async ({ id, userId }: GetTemplateByIdOptions) => {
const whereFilter: Prisma.TemplateWhereInput = {
id,
OR: [
{
userId,
},
{
team: {
members: {
some: {
userId,
},
},
},
},
],
};
return await prisma.template.findFirstOrThrow({
where: whereFilter,
include: {
templateDocumentData: true,
templateDocumentMeta: true,
},
});
};