mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 09:12:02 +10:00
feat: add support for attachments in template management
- Enhanced TemplateEditForm to include attachments in the template data. - Updated createDocumentFromTemplate to handle attachment creation. - Modified updateTemplate to manage attachment updates and deletions. - Integrated attachments into ZTemplateSchema and ZAddTemplateSettingsFormSchema for validation. - Improved getTemplateById to fetch attachments alongside other template data.
This commit is contained in:
@ -296,6 +296,7 @@ export const createDocumentFromTemplate = async ({
|
||||
fields: true,
|
||||
},
|
||||
},
|
||||
attachments: true,
|
||||
templateDocumentData: true,
|
||||
templateMeta: true,
|
||||
team: {
|
||||
@ -385,6 +386,15 @@ export const createDocumentFromTemplate = async ({
|
||||
}),
|
||||
visibility: template.visibility || template.team?.teamGlobalSettings?.documentVisibility,
|
||||
useLegacyFieldInsertion: template.useLegacyFieldInsertion ?? false,
|
||||
attachments: {
|
||||
create: template.attachments.map((attachment) => ({
|
||||
type: attachment.type,
|
||||
label: attachment.label,
|
||||
url: attachment.url,
|
||||
createdAt: attachment.createdAt,
|
||||
updatedAt: attachment.updatedAt,
|
||||
})),
|
||||
},
|
||||
documentMeta: {
|
||||
create: {
|
||||
subject: override?.subject || template.templateMeta?.subject,
|
||||
|
||||
@ -34,6 +34,7 @@ export const getTemplateById = async ({ id, userId, teamId }: GetTemplateByIdOpt
|
||||
templateMeta: true,
|
||||
recipients: true,
|
||||
fields: true,
|
||||
attachments: true,
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import type { DocumentVisibility, Template, TemplateMeta } from '@prisma/client';
|
||||
import type { Attachment, DocumentVisibility, Template, TemplateMeta } from '@prisma/client';
|
||||
|
||||
import { isUserEnterprise } from '@documenso/ee/server-only/util/is-document-enterprise';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
@ -21,6 +21,7 @@ export type UpdateTemplateOptions = {
|
||||
publicDescription?: string;
|
||||
type?: Template['type'];
|
||||
useLegacyFieldInsertion?: boolean;
|
||||
attachments?: Pick<Attachment, 'id' | 'label' | 'url'>[];
|
||||
};
|
||||
meta?: Partial<Omit<TemplateMeta, 'id' | 'templateId'>>;
|
||||
};
|
||||
@ -53,6 +54,7 @@ export const updateTemplate = async ({
|
||||
},
|
||||
include: {
|
||||
templateMeta: true,
|
||||
attachments: true,
|
||||
},
|
||||
});
|
||||
|
||||
@ -104,6 +106,29 @@ export const updateTemplate = async ({
|
||||
publicDescription: data?.publicDescription,
|
||||
publicTitle: data?.publicTitle,
|
||||
useLegacyFieldInsertion: data?.useLegacyFieldInsertion,
|
||||
attachments: {
|
||||
deleteMany: {
|
||||
templateId,
|
||||
id: {
|
||||
notIn: data?.attachments?.map((attachment) => attachment.id),
|
||||
},
|
||||
},
|
||||
upsert: data?.attachments?.map((attachment) => ({
|
||||
where: {
|
||||
id: attachment.id,
|
||||
templateId,
|
||||
},
|
||||
update: {
|
||||
label: attachment.label,
|
||||
url: attachment.url,
|
||||
},
|
||||
create: {
|
||||
id: attachment.id,
|
||||
label: attachment.label,
|
||||
url: attachment.url,
|
||||
},
|
||||
})),
|
||||
},
|
||||
authOptions,
|
||||
templateMeta: {
|
||||
upsert: {
|
||||
|
||||
Reference in New Issue
Block a user