mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 01:01:49 +10:00
feat: add sending pending email queue
This commit is contained in:
@ -8,9 +8,9 @@ import { DocumentStatus, SigningStatus } from '@documenso/prisma/client';
|
|||||||
import { WebhookTriggerEvents } from '@documenso/prisma/client';
|
import { WebhookTriggerEvents } from '@documenso/prisma/client';
|
||||||
|
|
||||||
import type { TRecipientActionAuth } from '../../types/document-auth';
|
import type { TRecipientActionAuth } from '../../types/document-auth';
|
||||||
|
import { queueJob } from '../queue/job';
|
||||||
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
||||||
import { sealDocument } from './seal-document';
|
import { sealDocument } from './seal-document';
|
||||||
import { sendPendingEmail } from './send-pending-email';
|
|
||||||
|
|
||||||
export type CompleteDocumentWithTokenOptions = {
|
export type CompleteDocumentWithTokenOptions = {
|
||||||
token: string;
|
token: string;
|
||||||
@ -134,7 +134,13 @@ export const completeDocumentWithToken = async ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (pendingRecipients > 0) {
|
if (pendingRecipients > 0) {
|
||||||
await sendPendingEmail({ documentId, recipientId: recipient.id });
|
await queueJob({
|
||||||
|
job: 'send-pending-email',
|
||||||
|
args: {
|
||||||
|
documentId: document.id,
|
||||||
|
recipientId: recipient.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const documents = await prisma.document.updateMany({
|
const documents = await prisma.document.updateMany({
|
||||||
|
|||||||
@ -5,18 +5,26 @@ import {
|
|||||||
type SendDocumentOptions as SendCompletedDocumentOptions,
|
type SendDocumentOptions as SendCompletedDocumentOptions,
|
||||||
sendCompletedEmail,
|
sendCompletedEmail,
|
||||||
} from '../document/send-completed-email';
|
} from '../document/send-completed-email';
|
||||||
|
import { type SendPendingEmailOptions, sendPendingEmail } from '../document/send-pending-email';
|
||||||
|
|
||||||
type JobOptions = {
|
type JobOptions = {
|
||||||
'send-completed-email': SendCompletedDocumentOptions;
|
'send-completed-email': SendCompletedDocumentOptions;
|
||||||
|
'send-pending-email': SendPendingEmailOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const jobHandlers: {
|
export const jobHandlers: {
|
||||||
[K in keyof JobOptions]: WorkHandler<JobOptions[K]>;
|
[K in keyof JobOptions]: WorkHandler<JobOptions[K]>;
|
||||||
} = {
|
} = {
|
||||||
'send-completed-email': async ({ data }) => {
|
'send-completed-email': async ({ data: { documentId, requestMetadata } }) => {
|
||||||
await sendCompletedEmail({
|
await sendCompletedEmail({
|
||||||
documentId: data.documentId,
|
documentId,
|
||||||
requestMetadata: data.requestMetadata,
|
requestMetadata,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
'send-pending-email': async ({ data: { documentId, recipientId } }) => {
|
||||||
|
await sendPendingEmail({
|
||||||
|
documentId,
|
||||||
|
recipientId,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user