mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
🚸 🚚 rename signDocument to addDigitalSignature, sign only when signatures exist
This commit is contained in:
@ -7,7 +7,7 @@ import prisma from "@documenso/prisma";
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { Document as PrismaDocument } from "@prisma/client";
|
||||
import { getDocument } from "@documenso/lib/query";
|
||||
import { signDocument } from "@documenso/signing/signDocument";
|
||||
import { addDigitalSignature } from "@documenso/signing/addDigitalSignature";
|
||||
|
||||
async function getHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const user = await getUserFromToken(req, res);
|
||||
@ -25,9 +25,20 @@ async function getHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (!document)
|
||||
res.status(404).end(`No document with id ${documentId} found.`);
|
||||
|
||||
const signedDocumentAsBase64 = await signDocument(
|
||||
document.document.toString()
|
||||
);
|
||||
const signaturesCount = await prisma.signature.count({
|
||||
where: {
|
||||
Field: {
|
||||
documentId: document.id,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
let signedDocumentAsBase64 = document.document;
|
||||
|
||||
// No need to add a signature, if no one signed yet.
|
||||
if (signaturesCount > 0) {
|
||||
signedDocumentAsBase64 = await addDigitalSignature(document.document);
|
||||
}
|
||||
|
||||
const buffer: Buffer = Buffer.from(signedDocumentAsBase64, "base64");
|
||||
res.setHeader("Content-Type", "application/pdf");
|
||||
|
||||
@ -7,12 +7,14 @@ import prisma from "@documenso/prisma";
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { Document as PrismaDocument } from "@prisma/client";
|
||||
import { getDocument } from "@documenso/lib/query";
|
||||
import { signDocument } from "@documenso/signing/signDocument";
|
||||
import { addDigitalSignature } from "@documenso/signing/addDigitalSignature";
|
||||
|
||||
async function getHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const documentId = req.query.id || 1;
|
||||
const document: PrismaDocument = await getDocument(+documentId, req, res);
|
||||
const signedDocumentAsBase64 = await signDocument(document.document.toString());
|
||||
const signedDocumentAsBase64 = await addDigitalSignature(
|
||||
document.document.toString()
|
||||
);
|
||||
const buffer: Buffer = Buffer.from(signedDocumentAsBase64, "base64");
|
||||
res.setHeader("Content-Type", "application/pdf");
|
||||
res.setHeader(
|
||||
|
||||
Reference in New Issue
Block a user