mirror of
https://github.com/documenso/documenso.git
synced 2025-11-24 05:32:12 +10:00
extend webhook triggers
This commit is contained in:
@ -3,6 +3,10 @@ import type { RequestMetadata } from '@documenso/lib/universal/extract-request-m
|
||||
import { createDocumentAuditLogData } from '@documenso/lib/utils/document-audit-logs';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import { ReadStatus } from '@documenso/prisma/client';
|
||||
import { WebhookTriggerEvents } from '@documenso/prisma/client';
|
||||
|
||||
import { triggerWebhook } from '../../universal/trigger-webhook';
|
||||
import { getDocumentAndSenderByToken } from './get-document-by-token';
|
||||
|
||||
export type ViewedDocumentOptions = {
|
||||
token: string;
|
||||
@ -23,8 +27,8 @@ export const viewedDocument = async ({ token, requestMetadata }: ViewedDocumentO
|
||||
|
||||
const { documentId } = recipient;
|
||||
|
||||
await prisma.$transaction(async (tx) => {
|
||||
await tx.recipient.update({
|
||||
const { updatedRecipient } = await prisma.$transaction(async (tx) => {
|
||||
const updatedRecipient = await tx.recipient.update({
|
||||
where: {
|
||||
id: recipient.id,
|
||||
},
|
||||
@ -50,5 +54,25 @@ export const viewedDocument = async ({ token, requestMetadata }: ViewedDocumentO
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
return { updatedRecipient };
|
||||
});
|
||||
|
||||
const document = await getDocumentAndSenderByToken({ token });
|
||||
|
||||
await triggerWebhook({
|
||||
eventTrigger: WebhookTriggerEvents.DOCUMENT_OPENED,
|
||||
documentData: {
|
||||
id: document.id,
|
||||
userId: document.userId,
|
||||
title: document.title,
|
||||
status: document.status,
|
||||
documentDataId: document.documentDataId,
|
||||
createdAt: document.createdAt,
|
||||
updatedAt: document.updatedAt,
|
||||
completedAt: document.completedAt,
|
||||
deletedAt: document.deletedAt,
|
||||
teamId: document.teamId,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user