From d6e3b2b5dc3899c75c42d70028eb112e01eea40f Mon Sep 17 00:00:00 2001 From: Catalin Pit Date: Thu, 2 Nov 2023 03:47:19 +0200 Subject: [PATCH] fix: seal document for single player mode (#617) --- .../create-single-player-document.action.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/marketing/src/components/(marketing)/single-player-mode/create-single-player-document.action.ts b/apps/marketing/src/components/(marketing)/single-player-mode/create-single-player-document.action.ts index 1e779fcfc..2cfd621e1 100644 --- a/apps/marketing/src/components/(marketing)/single-player-mode/create-single-player-document.action.ts +++ b/apps/marketing/src/components/(marketing)/single-player-mode/create-single-player-document.action.ts @@ -11,6 +11,7 @@ import { mailer } from '@documenso/email/mailer'; import { render } from '@documenso/email/render'; import { DocumentSelfSignedEmailTemplate } from '@documenso/email/templates/document-self-signed'; import { FROM_ADDRESS, FROM_NAME, SERVICE_USER_EMAIL } from '@documenso/lib/constants/email'; +import { sealDocument } from '@documenso/lib/server-only/document/seal-document'; import { insertFieldInPDF } from '@documenso/lib/server-only/pdf/insert-field-in-pdf'; import { alphaid } from '@documenso/lib/universal/id'; import { getFile } from '@documenso/lib/universal/upload/get-file'; @@ -99,9 +100,12 @@ export const createSinglePlayerDocument = async ( const pdfBytes = await doc.save(); - const documentToken = await prisma.$transaction( + const { + document: { id: documentId }, + token, + } = await prisma.$transaction( async (tx) => { - const documentToken = alphaid(); + const token = alphaid(); // Fetch service user who will be the owner of the document. const serviceUser = await tx.user.findFirstOrThrow({ @@ -137,7 +141,7 @@ export const createSinglePlayerDocument = async ( documentId: document.id, name: signer.name, email: signer.email, - token: documentToken, + token, signedAt: createdAt, readStatus: ReadStatus.OPENED, signingStatus: SigningStatus.SIGNED, @@ -169,7 +173,7 @@ export const createSinglePlayerDocument = async ( }), ); - return documentToken; + return { document, token }; }, { maxWait: 5000, @@ -177,6 +181,11 @@ export const createSinglePlayerDocument = async ( }, ); + await sealDocument({ + documentId, + sendEmail: false, + }); + const template = createElement(DocumentSelfSignedEmailTemplate, { documentName: documentName, assetBaseUrl: process.env.NEXT_PUBLIC_WEBAPP_URL || 'http://localhost:3000', @@ -198,7 +207,7 @@ export const createSinglePlayerDocument = async ( attachments: [{ content: Buffer.from(pdfBytes), filename: documentName }], }); - return documentToken; + return token; }; /**