mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
refactor: pass document id as arguments
This commit is contained in:
committed by
Mythie
parent
94215fffbb
commit
f18010e1e1
@ -71,7 +71,7 @@ export const completeDocumentWithToken = async ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// TODO: Send email to documents with two or more recipients
|
// TODO: Send email to documents with two or more recipients
|
||||||
await sendPendingEmail({ document, recipient });
|
await sendPendingEmail({ documentId, recipientId: recipient.id });
|
||||||
|
|
||||||
const documents = await prisma.document.updateMany({
|
const documents = await prisma.document.updateMany({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@ -3,14 +3,42 @@ import { createElement } from 'react';
|
|||||||
import { mailer } from '@documenso/email/mailer';
|
import { mailer } from '@documenso/email/mailer';
|
||||||
import { render } from '@documenso/email/render';
|
import { render } from '@documenso/email/render';
|
||||||
import { DocumentPendingEmailTemplate } from '@documenso/email/templates/document-pending';
|
import { DocumentPendingEmailTemplate } from '@documenso/email/templates/document-pending';
|
||||||
import { Document, Recipient } from '@documenso/prisma/client';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
export interface SendPendingEmailOptions {
|
export interface SendPendingEmailOptions {
|
||||||
document: Document;
|
documentId: number;
|
||||||
recipient: Recipient;
|
recipientId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const sendPendingEmail = async ({ document, recipient }: SendPendingEmailOptions) => {
|
export const sendPendingEmail = async ({ documentId, recipientId }: SendPendingEmailOptions) => {
|
||||||
|
const document = await prisma.document.findFirst({
|
||||||
|
where: {
|
||||||
|
id: documentId,
|
||||||
|
Recipient: {
|
||||||
|
some: {
|
||||||
|
id: recipientId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
Recipient: {
|
||||||
|
where: {
|
||||||
|
id: recipientId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!document) {
|
||||||
|
throw new Error('Document not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document.Recipient.length === 0) {
|
||||||
|
throw new Error('Document has no recipients');
|
||||||
|
}
|
||||||
|
|
||||||
|
const [recipient] = document.Recipient;
|
||||||
|
|
||||||
const { email, name } = recipient;
|
const { email, name } = recipient;
|
||||||
|
|
||||||
const assetBaseUrl = process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:3000';
|
const assetBaseUrl = process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:3000';
|
||||||
|
|||||||
Reference in New Issue
Block a user