Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trying to fix wrong consent expiration mail #553

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions apps/api/src/tasks/bank-import/import-transactions.task.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,7 @@ describe('ImportTransactionsTask', () => {

it('should handle USD currency and parse the BGN equivalent from the transactionId', () => {
const eurTransaction: IrisTransactionInfo = {
transactionId:
'Booked_6516347588_70001524349032963FTRO23184809601C2023010361.12_20230103',
transactionId: 'Booked_6516347588_70001524349032963FTRO23184809601C2023010361.12_20230103',
bookingDate: '2023-01-03',
creditorAccount: {
iban: 'BG66UNCR70001524349032',
Expand Down Expand Up @@ -764,8 +763,14 @@ describe('ImportTransactionsTask', () => {
consents: [
{
iban: IBAN,
status: 'valid',
validUntil: DateTime.now().plus({ days: 3 }).toFormat('yyyy-MM-dd'),
},
{
iban: IBAN,
status: 'expired',
validUntil: DateTime.now().minus({ days: 3 }).toFormat('yyyy-MM-dd'),
},
],
},
})
Expand All @@ -781,6 +786,7 @@ describe('ImportTransactionsTask', () => {

// 3 < 5 => notify for expiring consent
expect(getConsentLinkSpy).toHaveBeenCalled()

expect(emailService.sendFromTemplate).toHaveBeenCalled()
})
})
Expand All @@ -805,6 +811,7 @@ describe('ImportTransactionsTask', () => {
consents: [
{
iban: IBAN,
status: 'valid',
validUntil: DateTime.now().plus({ days: 6 }).toFormat('yyyy-MM-dd'),
},
],
Expand Down
16 changes: 9 additions & 7 deletions apps/api/src/tasks/bank-import/import-transactions.task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ export class IrisTasks {
})
).data

// Filter to current IBAN
const consent = consents.consents.find((consent) => consent.iban.trim() === this.IBAN)
// Filter valid consents to the current IBAN
const consent = consents.consents.find(
(consent) => consent.iban.trim() === this.IBAN && consent.status === 'valid',
)

if (!consent) return

const expDate = DateTime.fromFormat(consent.validUntil, 'yyyy-MM-dd')
const daysToExpire = Math.ceil(expDate.diff(DateTime.local(), 'days').toObject().days || 0)
const expDate = consent
? DateTime.fromFormat(consent.validUntil, 'yyyy-MM-dd')
: DateTime.local() //if no valid consent use today to send mail with days to expire 0
const daysToExpire = Math.ceil(expDate.diff(DateTime.local(), 'days').days || 0)

// If less than 5 days till expiration -> notify
if (daysToExpire <= this.daysToExpCondition) {
Expand All @@ -107,7 +109,7 @@ export class IrisTasks {
const recepient = { to: [this.billingAdminEmail] }
const mail = new ExpiringIrisConsentEmailDto({
daysToExpire,
expiresAt: consent.validUntil,
expiresAt: expDate.toISODate(),
renewLink,
})

Expand Down
Loading