From 3895b54c55dff12a5b2f3669e6351e6c10a0ce13 Mon Sep 17 00:00:00 2001 From: Patrick Venetz Date: Mon, 16 Nov 2020 08:56:44 +0100 Subject: [PATCH 1/2] fix(republik-crowdfundings): Set initial value on Array.reduce to 0 Array insertPromises might be an empty array. Setting initial value prevents error "Reduce of empty array with no initial value". --- packages/republik-crowdfundings/lib/scheduler/importPayments.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/republik-crowdfundings/lib/scheduler/importPayments.ts b/packages/republik-crowdfundings/lib/scheduler/importPayments.ts index 3bf412a72..ee27b2684 100644 --- a/packages/republik-crowdfundings/lib/scheduler/importPayments.ts +++ b/packages/republik-crowdfundings/lib/scheduler/importPayments.ts @@ -257,7 +257,7 @@ const insertPayments = async ({ return await postfinancePaymentsTable.insert(record) }) - return (await Promise.all(insertPromises)).reduce((a, b) => a + b) + return (await Promise.all(insertPromises)).reduce((a, b) => a + b, 0) } interface PostfinancePaymentRecord { From 0ecb1cf5ab1287d25b22e3759b8dbd89a5fb7044 Mon Sep 17 00:00:00 2001 From: Patrick Venetz Date: Mon, 16 Nov 2020 09:07:14 +0100 Subject: [PATCH 2/2] fix(republik-crowdfundings): Remove action required notice in Slack report Finance is canceling pledges at their own discretion and find action required notice unhelpful. --- .../paymentslip/sendPaymentReminders.ts | 41 ++++--------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/packages/republik-crowdfundings/lib/payments/paymentslip/sendPaymentReminders.ts b/packages/republik-crowdfundings/lib/payments/paymentslip/sendPaymentReminders.ts index 95473f342..9b56cfc7f 100644 --- a/packages/republik-crowdfundings/lib/payments/paymentslip/sendPaymentReminders.ts +++ b/packages/republik-crowdfundings/lib/payments/paymentslip/sendPaymentReminders.ts @@ -17,8 +17,7 @@ const DRY_RUN = process.env.DRY_RUN_SEND_PAYMENT_REMINDERS === 'true' const FIRST_REMINDER_DEADLINE_DAYS = PAYMENT_DEADLINE_DAYS + 3 // 3 days to consider weekends const SECOND_REMINDER_DEADLINE_DAYS = FIRST_REMINDER_DEADLINE_DAYS + 30 -const CANCEL_PLEDGE_DEADLINE_DAYS = SECOND_REMINDER_DEADLINE_DAYS + 15 -const DAYS_TO_CONSIDER = CANCEL_PLEDGE_DEADLINE_DAYS + 30 +const DAYS_TO_CONSIDER = SECOND_REMINDER_DEADLINE_DAYS + 30 interface OutstandingPayment { paymentId: Nominal @@ -46,19 +45,16 @@ export async function sendPaymentReminders( const [ firstRemindersSent, - secondRemindersSent, - cancelMessages, + secondRemindersSent ] = await Promise.all([ sendFirstReminder(outstandingPayments, context, dryRun), - sendSecondReminder(outstandingPayments, context, dryRun), - getMessageForAccountsToCancel(outstandingPayments), + sendSecondReminder(outstandingPayments, context, dryRun) ]) const message = generateReport({ dryRun, firstRemindersSent, - secondRemindersSent, - cancelMessages, + secondRemindersSent }) await publishFinance(message) @@ -68,42 +64,19 @@ export async function sendPaymentReminders( function generateReport({ dryRun, firstRemindersSent, - secondRemindersSent, - cancelMessages, + secondRemindersSent }: { dryRun: boolean firstRemindersSent: number secondRemindersSent: number - cancelMessages: string[] }) { - let messageLines = [ + return [ ...(dryRun ? ['⚠️ DRY RUN, REMINDERS ARE NOT SENT ⚠️'] : []), '💌 Reminders Sent', '', `First reminders sent: ${firstRemindersSent}`, `SecondRemindersSent: ${secondRemindersSent}`, - ] - - if (cancelMessages.length) { - messageLines = [ - ...messageLines, - '', - '🚨 Action Required - Cancel Pledges 🚨', - ...cancelMessages, - ] - } - - const message = messageLines.join('\n') - return message -} - -function getMessageForAccountsToCancel( - outstandingPayments: OutstandingPayment[], -) { - const filterDate = daysAgo(CANCEL_PLEDGE_DEADLINE_DAYS) - return outstandingPayments - .filter(({ createdAt }) => createdAt < filterDate) - .map(paymentToMessage) + ].join('\n') } function paymentToMessage({ userId, pledgeId }: OutstandingPayment) {