mirror of
https://github.com/documenso/documenso.git
synced 2026-07-24 17:04:12 +10:00
chore: code changes based of review
This commit is contained in:
@@ -106,23 +106,6 @@ export const resendDocument = async ({
|
||||
return;
|
||||
}
|
||||
|
||||
let newExpiryDate: Date | null = null;
|
||||
if (recipient.expired) {
|
||||
const durationInMs = recipient.expired.getTime() - document.updatedAt.getTime();
|
||||
newExpiryDate = new Date(Date.now() + durationInMs);
|
||||
|
||||
await prisma.recipient.update({
|
||||
where: { id: recipient.id },
|
||||
data: {
|
||||
expired: newExpiryDate,
|
||||
signingStatus:
|
||||
recipient.signingStatus === SigningStatus.EXPIRED
|
||||
? SigningStatus.NOT_SIGNED
|
||||
: recipient.signingStatus,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const i18n = await getI18nInstance(document.documentMeta?.language);
|
||||
|
||||
const recipientEmailType = RECIPIENT_ROLE_TO_EMAIL_TYPE[recipient.role];
|
||||
@@ -183,6 +166,22 @@ export const resendDocument = async ({
|
||||
|
||||
await prisma.$transaction(
|
||||
async (tx) => {
|
||||
if (recipient.expired) {
|
||||
const durationInMs = recipient.expired.getTime() - document.updatedAt.getTime();
|
||||
const newExpiryDate = new Date(Date.now() + durationInMs);
|
||||
|
||||
await tx.recipient.update({
|
||||
where: { id: recipient.id },
|
||||
data: {
|
||||
expired: newExpiryDate,
|
||||
signingStatus:
|
||||
recipient.signingStatus === SigningStatus.EXPIRED
|
||||
? SigningStatus.NOT_SIGNED
|
||||
: recipient.signingStatus,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const [html, text] = await Promise.all([
|
||||
renderEmailWithI18N(template, {
|
||||
lang: document.documentMeta?.language,
|
||||
|
||||
@@ -31,26 +31,24 @@ export const updateExpiredRecipients = async (documentId: number) => {
|
||||
},
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
expiredRecipients.map(async (recipient) =>
|
||||
prisma.documentAuditLog.create({
|
||||
data: createDocumentAuditLogData({
|
||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_EXPIRED,
|
||||
documentId,
|
||||
user: {
|
||||
name: recipient.name,
|
||||
email: recipient.email,
|
||||
},
|
||||
data: {
|
||||
recipientEmail: recipient.email,
|
||||
recipientName: recipient.name,
|
||||
recipientId: recipient.id,
|
||||
recipientRole: recipient.role,
|
||||
},
|
||||
}),
|
||||
await prisma.documentAuditLog.createMany({
|
||||
data: expiredRecipients.map((recipient) =>
|
||||
createDocumentAuditLogData({
|
||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_EXPIRED,
|
||||
documentId,
|
||||
user: {
|
||||
name: recipient.name,
|
||||
email: recipient.email,
|
||||
},
|
||||
data: {
|
||||
recipientName: recipient.name,
|
||||
recipientRole: recipient.role,
|
||||
recipientId: recipient.id,
|
||||
recipientEmail: recipient.email,
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return expiredRecipients;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import { SigningStatus } from '@documenso/prisma/client';
|
||||
|
||||
@@ -16,8 +18,8 @@ export const isRecipientExpired = async ({ token }: IsRecipientExpiredOptions) =
|
||||
throw new Error('Recipient not found');
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const hasExpired = recipient.expired && new Date(recipient.expired) <= now;
|
||||
const now = DateTime.now();
|
||||
const hasExpired = recipient.expired && DateTime.fromJSDate(recipient.expired) <= now;
|
||||
|
||||
if (hasExpired && recipient.signingStatus !== SigningStatus.EXPIRED) {
|
||||
await prisma.recipient.update({
|
||||
|
||||
@@ -103,9 +103,9 @@ export const setRecipientExpiry = async ({
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
return persisted;
|
||||
}
|
||||
|
||||
return persisted;
|
||||
});
|
||||
|
||||
return updatedRecipient;
|
||||
|
||||
@@ -375,7 +375,7 @@ export const formatDocumentAuditLogAction = (
|
||||
.with({ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_EXPIRED }, () => {
|
||||
const userName = prefix || _(msg`Recipient`);
|
||||
|
||||
const result = msg`${userName} expired`;
|
||||
const result = msg`${userName}'s signing period has expired`;
|
||||
|
||||
return {
|
||||
anonymous: result,
|
||||
|
||||
Reference in New Issue
Block a user