From c58006b2d97313c405afc045064f344630402c32 Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan Date: Thu, 7 Sep 2023 20:52:18 +0000 Subject: [PATCH] feat: avoid sending pending email to document with 1 recipients --- .../document/complete-document-with-token.ts | 11 +++++++++-- .../lib/server-only/document/send-completed-email.ts | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/lib/server-only/document/complete-document-with-token.ts b/packages/lib/server-only/document/complete-document-with-token.ts index ea440beb9..464b7fe4f 100644 --- a/packages/lib/server-only/document/complete-document-with-token.ts +++ b/packages/lib/server-only/document/complete-document-with-token.ts @@ -70,8 +70,15 @@ export const completeDocumentWithToken = async ({ }, }); - // TODO: Send email to documents with two or more recipients - await sendPendingEmail({ documentId, recipientId: recipient.id }); + const numberOfRecipients = await prisma.recipient.count({ + where: { + documentId: document.id, + }, + }); + + if (numberOfRecipients > 1) { + await sendPendingEmail({ documentId, recipientId: recipient.id }); + } const documents = await prisma.document.updateMany({ where: { diff --git a/packages/lib/server-only/document/send-completed-email.ts b/packages/lib/server-only/document/send-completed-email.ts index b8d50dba4..0a1817964 100644 --- a/packages/lib/server-only/document/send-completed-email.ts +++ b/packages/lib/server-only/document/send-completed-email.ts @@ -48,7 +48,7 @@ export const sendCompletedEmail = async ({ documentId }: SendDocumentOptions) => name: process.env.NEXT_PRIVATE_SMTP_FROM_NAME || 'Documenso', address: process.env.NEXT_PRIVATE_SMTP_FROM_ADDRESS || 'noreply@documenso.com', }, - subject: 'Everyone has signed!', + subject: 'Signing Complete!', html: render(template), text: render(template, { plainText: true }), });