Browse Source

Merge branch 'main' into feature/rename-order-to-activities-in-account-database-schema

pull/4577/head
Thomas Kaul 4 months ago
committed by GitHub
parent
commit
7a9bc22ba5
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      CHANGELOG.md
  2. 6
      apps/api/src/app/import/import.service.ts
  3. 21
      apps/api/src/validators/is-currency-code.ts
  4. 5
      apps/client/src/app/pages/portfolio/activities/import-activities-dialog/import-activities-dialog.component.ts

6
CHANGELOG.md

@ -9,8 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Improved the error message of the currency code validation
- Tightened the currency code validation by requiring uppercase letters
- Renamed `Order` to `activities` in the `Account` database schema - Renamed `Order` to `activities` in the `Account` database schema
### 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 ## 2.155.0 - 2025-04-23
### Added ### Added

6
apps/api/src/app/import/import.service.ts

@ -167,9 +167,9 @@ export class ImportService {
for (const account of accountsDto) { for (const account of accountsDto) {
// Check if there is any existing account with the same ID // Check if there is any existing account with the same ID
const accountWithSameId = existingAccounts.find( const accountWithSameId = existingAccounts.find((existingAccount) => {
(existingAccount) => existingAccount.id === account.id 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 there is no account or if the account belongs to a different user then create a new account
if (!accountWithSameId || accountWithSameId.userId !== user.id) { if (!accountWithSameId || accountWithSameId.userId !== user.id) {

21
apps/api/src/validators/is-currency-code.ts

@ -25,19 +25,24 @@ export class IsExtendedCurrencyConstraint
implements ValidatorConstraintInterface implements ValidatorConstraintInterface
{ {
public defaultMessage() { public defaultMessage() {
return '$value must be a valid ISO4217 currency code'; return '$property must be a valid ISO4217 currency code';
} }
public validate(currency: any) { public validate(currency: any) {
// Return true if currency is a standard ISO 4217 code or a derived currency // Return true if currency is a standard ISO 4217 code or a derived currency
return ( return (
isISO4217CurrencyCode(currency) || this.isUpperCase(currency) &&
[ (isISO4217CurrencyCode(currency) ||
...DERIVED_CURRENCIES.map((derivedCurrency) => { [
return derivedCurrency.currency; ...DERIVED_CURRENCIES.map((derivedCurrency) => {
}), return derivedCurrency.currency;
'USX' }),
].includes(currency) 'USX'
].includes(currency))
); );
} }
private isUpperCase(aString: string) {
return aString === aString?.toUpperCase();
}
} }

5
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) => { reader.onload = async (readerEvent) => {
const fileContent = readerEvent.target.result as string; const fileContent = readerEvent.target.result as string;
const fileExtension = file.name.split('.').pop()?.toLowerCase();
try { try {
if (file.name.endsWith('.json')) { if (fileExtension === 'json') {
const content = JSON.parse(fileContent); const content = JSON.parse(fileContent);
this.accounts = content.accounts; this.accounts = content.accounts;
@ -294,7 +295,7 @@ export class ImportActivitiesDialog implements OnDestroy {
} }
return; return;
} else if (file.name.endsWith('.csv')) { } else if (fileExtension === 'csv') {
const content = fileContent.split('\n').slice(1); const content = fileContent.split('\n').slice(1);
try { try {

Loading…
Cancel
Save