🚧 send signed notifcations

This commit is contained in:
Timur Ercan
2023-02-21 16:15:36 +01:00
parent ad2135d449
commit c016cb163e
3 changed files with 16 additions and 8 deletions

View File

@ -9,6 +9,7 @@ import { SigningStatus, DocumentStatus } from "@prisma/client";
import { getDocument } from "@documenso/lib/query";
import { Document as PrismaDocument } from "@prisma/client";
import { insertImageInPDF, insertTextInPDF } from "@documenso/pdf";
import { sendSigningDoneMail } from "@documenso/lib/mail";
async function postHandler(req: NextApiRequest, res: NextApiResponse) {
const existingUser = await getUserFromToken(req, res);
@ -83,6 +84,15 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
},
});
if (unsignedRecipients.length === 0) {
const documentOwner = await prisma.user.findFirstOrThrow({
where: { id: document.userId },
select: { email: true, name: true },
});
if (documentOwner) sendSigningDoneMail(recipient, document, documentOwner);
}
return res.status(200).end();
async function insertSignatureInDocument(signedField: any) {

View File

@ -1,3 +1,3 @@
export { sendSigningRequest as sendSigningRequest } from "./sendSigningRequest";
export { sendSignedMail } from "./sendSignedMail";
export { transactionEmailTemplate } from "./transactionEmailTemplate"
export { sendSigningDoneMail } from "./sendSigningDoneMail";
export { transactionEmailTemplate } from "./transactionEmailTemplate";

View File

@ -2,7 +2,7 @@ import { sendMail } from "./sendMail";
import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib/constants";
import { transactionEmailTemplate } from "@documenso/lib/mail";
export const sendSignedMail = async (
export const sendSigningDoneMail = async (
recipient: any,
document: any,
user: any
@ -12,13 +12,11 @@ export const sendSignedMail = async (
document.User.email,
`${recipient.email} signed "${document.title}"`,
transactionEmailTemplate(
`${document.User.name || recipient.email} has signed your document ${
document.title
}`,
`All recipients have signed your document ${document.title}`,
document,
recipient,
`${NEXT_PUBLIC_WEBAPP_URL}/documents/${document.id}`,
`View Document`,
`${NEXT_PUBLIC_WEBAPP_URL}/api/documents/${document.id}`,
`Download "${document.title}"`,
user
)
);