2024-04-18 17:47:50 +05:30
|
|
|
'use server';
|
|
|
|
|
|
|
|
|
|
import { prisma } from '@documenso/prisma';
|
|
|
|
|
|
|
|
|
|
export type CreateTemplateDocumentMetaOptions = {
|
|
|
|
|
templateId: number;
|
|
|
|
|
subject?: string;
|
|
|
|
|
message?: string;
|
|
|
|
|
timezone?: string;
|
|
|
|
|
password?: string;
|
|
|
|
|
dateFormat?: string;
|
|
|
|
|
redirectUrl?: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const upsertTemplateDocumentMeta = async ({
|
|
|
|
|
subject,
|
|
|
|
|
message,
|
|
|
|
|
timezone,
|
|
|
|
|
dateFormat,
|
|
|
|
|
templateId,
|
|
|
|
|
password,
|
|
|
|
|
redirectUrl,
|
|
|
|
|
}: CreateTemplateDocumentMetaOptions) => {
|
2024-05-09 12:35:32 +05:30
|
|
|
const templateDocumentMeta = await prisma.templateDocumentMeta.findFirstOrThrow({
|
|
|
|
|
where: {
|
|
|
|
|
templateId: templateId,
|
|
|
|
|
},
|
|
|
|
|
include: {
|
|
|
|
|
template: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
2024-04-18 17:47:50 +05:30
|
|
|
return await prisma.$transaction(async (tx) => {
|
|
|
|
|
const upsertedTemplateDocumentMeta = await tx.templateDocumentMeta.upsert({
|
|
|
|
|
where: {
|
|
|
|
|
templateId,
|
|
|
|
|
},
|
|
|
|
|
update: {
|
|
|
|
|
subject,
|
|
|
|
|
message,
|
|
|
|
|
timezone,
|
|
|
|
|
password,
|
|
|
|
|
dateFormat,
|
|
|
|
|
redirectUrl,
|
|
|
|
|
},
|
|
|
|
|
create: {
|
|
|
|
|
templateId,
|
|
|
|
|
subject,
|
|
|
|
|
message,
|
|
|
|
|
timezone,
|
|
|
|
|
password,
|
|
|
|
|
dateFormat,
|
|
|
|
|
redirectUrl,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return upsertedTemplateDocumentMeta;
|
|
|
|
|
});
|
|
|
|
|
};
|