fix: build errors

This commit is contained in:
Ephraim Atta-Duncan
2025-10-20 12:58:29 +00:00
parent 79506d5973
commit e6f482b4d2

View File

@ -27,10 +27,10 @@ export async function run({ io, intervals }: SendReminderHandlerOptions) {
const now = new Date(); const now = new Date();
const intervalsString = intervals.join(',').toLowerCase(); const intervalsString = intervals.join(',').toLowerCase();
const documentsToSendReminders = await io.runTask( const envelopesToSendReminders = await io.runTask(
`find-documents-for-${intervalsString}-reminder`, `find-documents-for-${intervalsString}-reminder`,
async () => { async () => {
const documents = await prisma.document.findMany({ const envelopes = await prisma.envelope.findMany({
where: { where: {
status: DocumentStatus.PENDING, status: DocumentStatus.PENDING,
documentMeta: { documentMeta: {
@ -54,10 +54,10 @@ export async function run({ io, intervals }: SendReminderHandlerOptions) {
}, },
}); });
const filteredDocuments = documents.filter((document) => { const filteredEnvelopes = envelopes.filter((envelope) => {
const { documentMeta } = document; const { documentMeta } = envelope;
if (!documentMeta) { if (!documentMeta) {
io.logger.warn(`Filtering out document ${document.id} due to missing documentMeta.`); io.logger.warn(`Filtering out envelope ${envelope.id} due to missing documentMeta.`);
return false; return false;
} }
@ -72,46 +72,46 @@ export async function run({ io, intervals }: SendReminderHandlerOptions) {
}); });
io.logger.info( io.logger.info(
`Found ${filteredDocuments.length} documents after filtering for interval ${intervalsString}.`, `Found ${filteredEnvelopes.length} envelopes after filtering for interval ${intervalsString}.`,
filteredDocuments.map((d) => ({ id: d.id })), filteredEnvelopes.map((e) => ({ id: e.id })),
); );
return filteredDocuments; return filteredEnvelopes;
}, },
); );
if (documentsToSendReminders.length === 0) { if (envelopesToSendReminders.length === 0) {
io.logger.info(`No documents found needing ${intervalsString} reminders.`); io.logger.info(`No envelopes found needing ${intervalsString} reminders.`);
return; return;
} }
io.logger.info( io.logger.info(
`Found ${documentsToSendReminders.length} documents needing ${intervalsString} reminders.`, `Found ${envelopesToSendReminders.length} envelopes needing ${intervalsString} reminders.`,
); );
for (const document of documentsToSendReminders) { for (const envelope of envelopesToSendReminders) {
if (!document.documentMeta) { if (!envelope.documentMeta) {
io.logger.warn(`Skipping document ${document.id} due to missing documentMeta.`); io.logger.warn(`Skipping envelope ${envelope.id} due to missing documentMeta.`);
continue; continue;
} }
if (!extractDerivedDocumentEmailSettings(document.documentMeta).recipientSigningRequest) { if (!extractDerivedDocumentEmailSettings(envelope.documentMeta).recipientSigningRequest) {
io.logger.info(`Skipping document ${document.id} due to email settings.`); io.logger.info(`Skipping envelope ${envelope.id} due to email settings.`);
continue; continue;
} }
for (const recipient of document.recipients) { for (const recipient of envelope.recipients) {
try { try {
const i18n = await getI18nInstance(document.documentMeta.language); const i18n = await getI18nInstance(envelope.documentMeta.language);
const recipientActionVerb = i18n const recipientActionVerb = i18n
._(RECIPIENT_ROLES_DESCRIPTION[recipient.role].actionVerb) ._(RECIPIENT_ROLES_DESCRIPTION[recipient.role].actionVerb)
.toLowerCase(); .toLowerCase();
const emailSubject = i18n._( const emailSubject = i18n._(
msg`Reminder: Please ${recipientActionVerb} the document "${document.title}"`, msg`Reminder: Please ${recipientActionVerb} the document "${envelope.title}"`,
); );
const emailMessage = i18n._( const emailMessage = i18n._(
msg`This is a reminder to ${recipientActionVerb} the document "${document.title}". Please complete this at your earliest convenience.`, msg`This is a reminder to ${recipientActionVerb} the document "${envelope.title}". Please complete this at your earliest convenience.`,
); );
const signDocumentLink = `${NEXT_PUBLIC_WEBAPP_URL()}/sign/${recipient.token}`; const signDocumentLink = `${NEXT_PUBLIC_WEBAPP_URL()}/sign/${recipient.token}`;
@ -119,7 +119,7 @@ export async function run({ io, intervals }: SendReminderHandlerOptions) {
const template = createElement(DocumentReminderEmailTemplate, { const template = createElement(DocumentReminderEmailTemplate, {
recipientName: recipient.name, recipientName: recipient.name,
documentName: document.title, documentName: envelope.title,
assetBaseUrl, assetBaseUrl,
signDocumentLink, signDocumentLink,
customBody: emailMessage, customBody: emailMessage,
@ -128,9 +128,9 @@ export async function run({ io, intervals }: SendReminderHandlerOptions) {
await io.runTask(`send-reminder-${recipient.id}`, async () => { await io.runTask(`send-reminder-${recipient.id}`, async () => {
const [html, text] = await Promise.all([ const [html, text] = await Promise.all([
renderEmailWithI18N(template, { lang: document.documentMeta?.language }), renderEmailWithI18N(template, { lang: envelope.documentMeta?.language }),
renderEmailWithI18N(template, { renderEmailWithI18N(template, {
lang: document.documentMeta?.language, lang: envelope.documentMeta?.language,
plainText: true, plainText: true,
}), }),
]); ]);
@ -159,8 +159,8 @@ export async function run({ io, intervals }: SendReminderHandlerOptions) {
await prisma.documentAuditLog.create({ await prisma.documentAuditLog.create({
data: { data: {
type: DOCUMENT_AUDIT_LOG_TYPE.EMAIL_SENT, type: DOCUMENT_AUDIT_LOG_TYPE.EMAIL_SENT,
documentId: document.id, envelopeId: envelope.id,
userId: document.userId, userId: envelope.userId,
data: { data: {
type: DOCUMENT_AUDIT_LOG_TYPE.EMAIL_SENT, type: DOCUMENT_AUDIT_LOG_TYPE.EMAIL_SENT,
data: { data: {
@ -182,15 +182,15 @@ export async function run({ io, intervals }: SendReminderHandlerOptions) {
} }
try { try {
await io.runTask(`update-meta-${document.id}`, async () => { await io.runTask(`update-meta-${envelope.id}`, async () => {
await prisma.documentMeta.update({ await prisma.documentMeta.update({
where: { documentId: document.id }, where: { id: envelope.documentMetaId },
data: { lastReminderSentAt: now }, data: { lastReminderSentAt: now },
}); });
}); });
io.logger.info(`Updated lastReminderSentAt for document ${document.id}`); io.logger.info(`Updated lastReminderSentAt for envelope ${envelope.id}`);
} catch (error) { } catch (error) {
io.logger.error(`Error updating lastReminderSentAt for document ${document.id}`, error); io.logger.error(`Error updating lastReminderSentAt for envelope ${envelope.id}`, error);
} }
} }
} }