mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
37 lines
715 B
TypeScript
37 lines
715 B
TypeScript
import { prisma } from '@documenso/prisma';
|
|
import type { TCreateTemplateMutationSchema } from '@documenso/trpc/server/template-router/schema';
|
|
|
|
export type CreateTemplateOptions = TCreateTemplateMutationSchema & {
|
|
userId: number;
|
|
teamId?: number;
|
|
};
|
|
|
|
export const createTemplate = async ({
|
|
title,
|
|
userId,
|
|
teamId,
|
|
templateDocumentDataId,
|
|
}: CreateTemplateOptions) => {
|
|
if (teamId) {
|
|
await prisma.team.findFirstOrThrow({
|
|
where: {
|
|
id: teamId,
|
|
members: {
|
|
some: {
|
|
userId,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
return await prisma.template.create({
|
|
data: {
|
|
title,
|
|
userId,
|
|
templateDocumentDataId,
|
|
teamId,
|
|
},
|
|
});
|
|
};
|