feat: prevent signing when expired

This commit is contained in:
Ephraim Atta-Duncan
2024-11-17 12:12:27 +00:00
parent 79d0cd7de5
commit 316dbee446
5 changed files with 146 additions and 17 deletions

View File

@ -0,0 +1,34 @@
import { prisma } from '@documenso/prisma';
import { SigningStatus } from '@documenso/prisma/client';
export type IsRecipientExpiredOptions = {
token: string;
};
export const isRecipientExpired = async ({ token }: IsRecipientExpiredOptions) => {
const recipient = await prisma.recipient.findFirst({
where: {
token,
},
});
if (!recipient) {
throw new Error('Recipient not found');
}
const now = new Date();
const hasExpired = recipient.expired && new Date(recipient.expired) <= now;
if (hasExpired && recipient.signingStatus !== SigningStatus.EXPIRED) {
await prisma.recipient.update({
where: {
id: recipient.id,
},
data: {
signingStatus: SigningStatus.EXPIRED,
},
});
}
return hasExpired;
};