Files
sign/packages/lib/server-only/template/create-template.ts

37 lines
715 B
TypeScript
Raw Normal View History

2023-10-06 22:54:24 +00:00
import { prisma } from '@documenso/prisma';
2024-02-08 12:33:20 +11:00
import type { TCreateTemplateMutationSchema } from '@documenso/trpc/server/template-router/schema';
2023-10-06 22:54:24 +00:00
export type CreateTemplateOptions = TCreateTemplateMutationSchema & {
userId: number;
2024-02-08 12:33:20 +11:00
teamId?: number;
2023-10-06 22:54:24 +00:00
};
export const createTemplate = async ({
title,
userId,
2024-02-08 12:33:20 +11:00
teamId,
2023-10-06 22:54:24 +00:00
templateDocumentDataId,
}: CreateTemplateOptions) => {
2024-02-08 12:33:20 +11:00
if (teamId) {
await prisma.team.findFirstOrThrow({
where: {
id: teamId,
members: {
some: {
userId,
},
},
},
});
}
2023-10-06 22:54:24 +00:00
return await prisma.template.create({
data: {
title,
userId,
templateDocumentDataId,
2024-02-08 12:33:20 +11:00
teamId,
2023-10-06 22:54:24 +00:00
},
});
};