mirror of
https://github.com/documenso/documenso.git
synced 2025-11-16 01:32:06 +10:00
fix: seal document for single player mode (#617)
This commit is contained in:
@ -11,6 +11,7 @@ import { mailer } from '@documenso/email/mailer';
|
|||||||
import { render } from '@documenso/email/render';
|
import { render } from '@documenso/email/render';
|
||||||
import { DocumentSelfSignedEmailTemplate } from '@documenso/email/templates/document-self-signed';
|
import { DocumentSelfSignedEmailTemplate } from '@documenso/email/templates/document-self-signed';
|
||||||
import { FROM_ADDRESS, FROM_NAME, SERVICE_USER_EMAIL } from '@documenso/lib/constants/email';
|
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 { insertFieldInPDF } from '@documenso/lib/server-only/pdf/insert-field-in-pdf';
|
||||||
import { alphaid } from '@documenso/lib/universal/id';
|
import { alphaid } from '@documenso/lib/universal/id';
|
||||||
import { getFile } from '@documenso/lib/universal/upload/get-file';
|
import { getFile } from '@documenso/lib/universal/upload/get-file';
|
||||||
@ -99,9 +100,12 @@ export const createSinglePlayerDocument = async (
|
|||||||
|
|
||||||
const pdfBytes = await doc.save();
|
const pdfBytes = await doc.save();
|
||||||
|
|
||||||
const documentToken = await prisma.$transaction(
|
const {
|
||||||
|
document: { id: documentId },
|
||||||
|
token,
|
||||||
|
} = await prisma.$transaction(
|
||||||
async (tx) => {
|
async (tx) => {
|
||||||
const documentToken = alphaid();
|
const token = alphaid();
|
||||||
|
|
||||||
// Fetch service user who will be the owner of the document.
|
// Fetch service user who will be the owner of the document.
|
||||||
const serviceUser = await tx.user.findFirstOrThrow({
|
const serviceUser = await tx.user.findFirstOrThrow({
|
||||||
@ -137,7 +141,7 @@ export const createSinglePlayerDocument = async (
|
|||||||
documentId: document.id,
|
documentId: document.id,
|
||||||
name: signer.name,
|
name: signer.name,
|
||||||
email: signer.email,
|
email: signer.email,
|
||||||
token: documentToken,
|
token,
|
||||||
signedAt: createdAt,
|
signedAt: createdAt,
|
||||||
readStatus: ReadStatus.OPENED,
|
readStatus: ReadStatus.OPENED,
|
||||||
signingStatus: SigningStatus.SIGNED,
|
signingStatus: SigningStatus.SIGNED,
|
||||||
@ -169,7 +173,7 @@ export const createSinglePlayerDocument = async (
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
return documentToken;
|
return { document, token };
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
maxWait: 5000,
|
maxWait: 5000,
|
||||||
@ -177,6 +181,11 @@ export const createSinglePlayerDocument = async (
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await sealDocument({
|
||||||
|
documentId,
|
||||||
|
sendEmail: false,
|
||||||
|
});
|
||||||
|
|
||||||
const template = createElement(DocumentSelfSignedEmailTemplate, {
|
const template = createElement(DocumentSelfSignedEmailTemplate, {
|
||||||
documentName: documentName,
|
documentName: documentName,
|
||||||
assetBaseUrl: process.env.NEXT_PUBLIC_WEBAPP_URL || 'http://localhost:3000',
|
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 }],
|
attachments: [{ content: Buffer.from(pdfBytes), filename: documentName }],
|
||||||
});
|
});
|
||||||
|
|
||||||
return documentToken;
|
return token;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user