mirror of
https://github.com/documenso/documenso.git
synced 2025-11-17 02:01:33 +10:00
feat: add template meta for templates
Signed-off-by: Adithya Krishna <aadithya794@gmail.com>
This commit is contained in:
@ -80,7 +80,7 @@ export const sendCompletedEmail = async ({ documentId, requestMetadata }: SendDo
|
||||
text: render(template, { plainText: true }),
|
||||
attachments: [
|
||||
{
|
||||
filename: document.title,
|
||||
filename: document.title.endsWith('.pdf') ? document.title : document.title + '.pdf',
|
||||
content: Buffer.from(completedDocument),
|
||||
},
|
||||
],
|
||||
|
||||
@ -0,0 +1,50 @@
|
||||
'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) => {
|
||||
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;
|
||||
});
|
||||
};
|
||||
@ -42,6 +42,7 @@ export const createDocumentFromTemplate = async ({
|
||||
Recipient: true,
|
||||
Field: true,
|
||||
templateDocumentData: true,
|
||||
templateDocumentMeta: true,
|
||||
},
|
||||
});
|
||||
|
||||
@ -57,12 +58,24 @@ export const createDocumentFromTemplate = async ({
|
||||
},
|
||||
});
|
||||
|
||||
// const templateDocumentMeta = await prisma.documentMeta.create({
|
||||
// data: {
|
||||
// subject: template.templateDocumentMeta.subject,
|
||||
// message: template.templateDocumentMeta.message,
|
||||
// timezone: template.templateDocumentMeta.timezone,
|
||||
// password: template.templateDocumentMeta.password,
|
||||
// dateFormat: template.templateDocumentMeta.dateFormat,
|
||||
// redirectUrl: template.templateDocumentMeta.redirectUrl,
|
||||
// },
|
||||
// });
|
||||
|
||||
const document = await prisma.document.create({
|
||||
data: {
|
||||
userId,
|
||||
teamId: template.teamId,
|
||||
title: template.title,
|
||||
documentDataId: documentData.id,
|
||||
// documentMeta: templateDocumentMeta,
|
||||
Recipient: {
|
||||
create: template.Recipient.map((recipient) => ({
|
||||
email: recipient.email,
|
||||
|
||||
@ -38,6 +38,7 @@ export const duplicateTemplate = async ({
|
||||
Recipient: true,
|
||||
Field: true,
|
||||
templateDocumentData: true,
|
||||
templateDocumentMeta: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -37,6 +37,7 @@ export const findTemplates = async ({
|
||||
where: whereFilter,
|
||||
include: {
|
||||
templateDocumentData: true,
|
||||
templateDocumentMeta: true,
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
@ -29,6 +29,7 @@ export const getTemplateById = async ({ id, userId }: GetTemplateByIdOptions) =>
|
||||
where: whereFilter,
|
||||
include: {
|
||||
templateDocumentData: true,
|
||||
templateDocumentMeta: true,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user