From a2902ee7c02f0652ac33d3518b4e3e3251c7d9e1 Mon Sep 17 00:00:00 2001 From: Mythie Date: Wed, 25 Oct 2023 22:34:51 +1100 Subject: [PATCH] fix: attach document to completed email --- .../lib/server-only/document/send-completed-email.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/lib/server-only/document/send-completed-email.ts b/packages/lib/server-only/document/send-completed-email.ts index 9d0d2d499..bb6d06b41 100644 --- a/packages/lib/server-only/document/send-completed-email.ts +++ b/packages/lib/server-only/document/send-completed-email.ts @@ -5,6 +5,8 @@ import { render } from '@documenso/email/render'; import { DocumentCompletedEmailTemplate } from '@documenso/email/templates/document-completed'; import { prisma } from '@documenso/prisma'; +import { getFile } from '../../universal/upload/get-file'; + export interface SendDocumentOptions { documentId: number; } @@ -15,6 +17,7 @@ export const sendCompletedEmail = async ({ documentId }: SendDocumentOptions) => id: documentId, }, include: { + documentData: true, Recipient: true, }, }); @@ -27,6 +30,8 @@ export const sendCompletedEmail = async ({ documentId }: SendDocumentOptions) => throw new Error('Document has no recipients'); } + const buffer = await getFile(document.documentData); + await Promise.all([ document.Recipient.map(async (recipient) => { const { email, name, token } = recipient; @@ -51,6 +56,12 @@ export const sendCompletedEmail = async ({ documentId }: SendDocumentOptions) => subject: 'Signing Complete!', html: render(template), text: render(template, { plainText: true }), + attachments: [ + { + filename: document.title, + content: Buffer.from(buffer), + }, + ], }); }), ]);