From 447fe1806fa4fb33fb2d97371b43dd6698909f59 Mon Sep 17 00:00:00 2001 From: Vinodh Zamboulingame <48854069+vzamboulingame@users.noreply.github.com> Date: Thu, 24 Apr 2025 20:40:12 +0200 Subject: [PATCH 1/3] Bugfix/fix activities import of files with extension in uppercase (#4596) * Fix activities import of files with extension in uppercase * Update changelog --- CHANGELOG.md | 6 ++++++ .../import-activities-dialog.component.ts | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcc336b31..db8312af0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Improved the file selector of the activities import functionality to accept case-insensitive file extensions (`.CSV` and `.JSON`) + ## 2.155.0 - 2025-04-23 ### Added diff --git a/apps/client/src/app/pages/portfolio/activities/import-activities-dialog/import-activities-dialog.component.ts b/apps/client/src/app/pages/portfolio/activities/import-activities-dialog/import-activities-dialog.component.ts index 82e78a180..20f135801 100644 --- a/apps/client/src/app/pages/portfolio/activities/import-activities-dialog/import-activities-dialog.component.ts +++ b/apps/client/src/app/pages/portfolio/activities/import-activities-dialog/import-activities-dialog.component.ts @@ -247,9 +247,10 @@ export class ImportActivitiesDialog implements OnDestroy { reader.onload = async (readerEvent) => { const fileContent = readerEvent.target.result as string; + const fileExtension = file.name.split('.').pop()?.toLowerCase(); try { - if (file.name.endsWith('.json')) { + if (fileExtension === 'json') { const content = JSON.parse(fileContent); this.accounts = content.accounts; @@ -294,7 +295,7 @@ export class ImportActivitiesDialog implements OnDestroy { } return; - } else if (file.name.endsWith('.csv')) { + } else if (fileExtension === 'csv') { const content = fileContent.split('\n').slice(1); try { From 3b59d7989a23c9dd6c59c12b604cb8ad0d6c801b Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Fri, 25 Apr 2025 08:24:16 +0200 Subject: [PATCH 2/3] Feature/improve currency code validation (#4598) * Improve currency code validation * Update changelog --- CHANGELOG.md | 5 +++++ apps/api/src/validators/is-currency-code.ts | 21 +++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db8312af0..328d7749e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +- Improved the error message of the currency code validation +- Tightened the currency code validation by requiring uppercase letters + ### Fixed - Improved the file selector of the activities import functionality to accept case-insensitive file extensions (`.CSV` and `.JSON`) diff --git a/apps/api/src/validators/is-currency-code.ts b/apps/api/src/validators/is-currency-code.ts index 34a82c481..d04da7808 100644 --- a/apps/api/src/validators/is-currency-code.ts +++ b/apps/api/src/validators/is-currency-code.ts @@ -25,19 +25,24 @@ export class IsExtendedCurrencyConstraint implements ValidatorConstraintInterface { public defaultMessage() { - return '$value must be a valid ISO4217 currency code'; + return '$property must be a valid ISO4217 currency code'; } public validate(currency: any) { // Return true if currency is a standard ISO 4217 code or a derived currency return ( - isISO4217CurrencyCode(currency) || - [ - ...DERIVED_CURRENCIES.map((derivedCurrency) => { - return derivedCurrency.currency; - }), - 'USX' - ].includes(currency) + this.isUpperCase(currency) && + (isISO4217CurrencyCode(currency) || + [ + ...DERIVED_CURRENCIES.map((derivedCurrency) => { + return derivedCurrency.currency; + }), + 'USX' + ].includes(currency)) ); } + + private isUpperCase(aString: string) { + return aString === aString?.toUpperCase(); + } } From 7fb0f9b6e8da4b8e7362704fa6640d820a5a191b Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 26 Apr 2025 07:02:31 +0200 Subject: [PATCH 3/3] Feature/refactor import service (#4599) * Refactoring --- apps/api/src/app/import/import.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/api/src/app/import/import.service.ts b/apps/api/src/app/import/import.service.ts index babe7c3e3..b6fe0d949 100644 --- a/apps/api/src/app/import/import.service.ts +++ b/apps/api/src/app/import/import.service.ts @@ -167,9 +167,9 @@ export class ImportService { for (const account of accountsDto) { // Check if there is any existing account with the same ID - const accountWithSameId = existingAccounts.find( - (existingAccount) => existingAccount.id === account.id - ); + const accountWithSameId = existingAccounts.find((existingAccount) => { + return existingAccount.id === account.id; + }); // If there is no account or if the account belongs to a different user then create a new account if (!accountWithSameId || accountWithSameId.userId !== user.id) {