mirror of
https://github.com/documenso/documenso.git
synced 2025-11-19 19:21:39 +10:00
feat: update recipient expiry handling
This commit is contained in:
@ -16,6 +16,7 @@ import type { TRecipientActionAuth } from '../../types/document-auth';
|
||||
import { getIsRecipientsTurnToSign } from '../recipient/get-is-recipient-turn';
|
||||
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
||||
import { sendPendingEmail } from './send-pending-email';
|
||||
import { updateExpiredRecipients } from './update-expired-recipients';
|
||||
|
||||
export type CompleteDocumentWithTokenOptions = {
|
||||
token: string;
|
||||
@ -61,12 +62,22 @@ export const completeDocumentWithToken = async ({
|
||||
throw new Error(`Document ${document.id} has no recipient with token ${token}`);
|
||||
}
|
||||
|
||||
await updateExpiredRecipients(documentId);
|
||||
|
||||
const [recipient] = document.Recipient;
|
||||
|
||||
if (recipient.expired && recipient.expired < new Date()) {
|
||||
throw new Error(`Recipient ${recipient.id} signature period has expired`);
|
||||
}
|
||||
|
||||
if (recipient.signingStatus === SigningStatus.SIGNED) {
|
||||
throw new Error(`Recipient ${recipient.id} has already signed`);
|
||||
}
|
||||
|
||||
if (recipient.signingStatus === SigningStatus.EXPIRED) {
|
||||
throw new Error(`Recipient ${recipient.id} signature period has expired`);
|
||||
}
|
||||
|
||||
if (document.documentMeta?.signingOrder === DocumentSigningOrder.SEQUENTIAL) {
|
||||
const isRecipientsTurn = await getIsRecipientsTurnToSign({ token: recipient.token });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user