chore: send document owner email

Signed-off-by: Adithya Krishna <aadithya794@gmail.com>
This commit is contained in:
Adithya Krishna
2024-03-15 22:26:31 +05:30
parent 52afae331e
commit f012826b6b
2 changed files with 15 additions and 6 deletions

View File

@ -12,6 +12,7 @@ import { DocumentStatus, RecipientRole, SigningStatus } from '@documenso/prisma/
import { WebhookTriggerEvents } from '@documenso/prisma/client';
import { signPdf } from '@documenso/signing';
import { getRequiredServerComponentSession } from '../../next-auth/get-server-component-session';
import type { RequestMetadata } from '../../universal/extract-request-metadata';
import { getFile } from '../../universal/upload/get-file';
import { putFile } from '../../universal/upload/put-file';
@ -46,6 +47,8 @@ export const sealDocument = async ({
const { documentData } = document;
const { user: documentOwner } = await getRequiredServerComponentSession();
if (!documentData) {
throw new Error(`Document ${document.id} has no document data`);
}
@ -169,7 +172,7 @@ export const sealDocument = async ({
});
if (sendEmail && !isResealing) {
await sendCompletedEmail({ documentId, requestMetadata });
await sendCompletedEmail({ documentId, requestMetadata, documentOwner });
}
await triggerWebhook({

View File

@ -4,20 +4,25 @@ import { mailer } from '@documenso/email/mailer';
import { render } from '@documenso/email/render';
import { DocumentCompletedEmailTemplate } from '@documenso/email/templates/document-completed';
import { prisma } from '@documenso/prisma';
import type { User } from '@documenso/prisma/client';
import { NEXT_PUBLIC_WEBAPP_URL } from '../../constants/app';
import { DOCUMENT_AUDIT_LOG_TYPE } from '../../types/document-audit-logs';
import type { RequestMetadata } from '../../universal/extract-request-metadata';
import { getFile } from '../../universal/upload/get-file';
import { createDocumentAuditLogData } from '../../utils/document-audit-logs';
import { getUserById } from '../user/get-user-by-id';
export interface SendDocumentOptions {
documentId: number;
requestMetadata?: RequestMetadata;
documentOwner: User;
}
export const sendCompletedEmail = async ({ documentId, requestMetadata }: SendDocumentOptions) => {
export const sendCompletedEmail = async ({
documentId,
requestMetadata,
documentOwner,
}: SendDocumentOptions) => {
const document = await prisma.document.findUnique({
where: {
id: documentId,
@ -41,7 +46,6 @@ export const sendCompletedEmail = async ({ documentId, requestMetadata }: SendDo
await Promise.all(
document.Recipient.map(async (recipient) => {
const { email, name, token } = recipient;
const user = await getUserById({ id: document.userId });
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
@ -55,13 +59,15 @@ export const sendCompletedEmail = async ({ documentId, requestMetadata }: SendDo
async (tx) => {
await mailer.sendMail({
to: [
// To send email to recipient of the document
{
address: email,
name,
},
// To send email to owner of the document
{
address: user.email,
name: user.name!,
address: documentOwner.email,
name: documentOwner.name!,
},
],
from: {