mirror of
https://github.com/documenso/documenso.git
synced 2025-11-20 03:32:14 +10:00
feat: prevent signing when expired
This commit is contained in:
34
packages/lib/server-only/recipient/is-recipient-expired.ts
Normal file
34
packages/lib/server-only/recipient/is-recipient-expired.ts
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user