From 88b8a6915798ac281ba86d4bf4dfaf95e02f6738 Mon Sep 17 00:00:00 2001 From: Arshad Jamal Date: Wed, 4 Oct 2023 00:28:45 +0530 Subject: [PATCH] Added all the recommended changes --- .../app/services/import-activities.service.ts | 42 +++++++++---------- test/import/ok.csv | 4 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/apps/client/src/app/services/import-activities.service.ts b/apps/client/src/app/services/import-activities.service.ts index f843ac43b..2a057bdd7 100644 --- a/apps/client/src/app/services/import-activities.service.ts +++ b/apps/client/src/app/services/import-activities.service.ts @@ -15,6 +15,7 @@ import { catchError } from 'rxjs/operators'; }) export class ImportActivitiesService { private static ACCOUNT_KEYS = ['account', 'accountid']; + private static COMMENT_KEYS = ["comment", "note"] private static CURRENCY_KEYS = ['ccy', 'currency', 'currencyprimary']; private static DATA_SOURCE_KEYS = ['datasource']; private static DATE_KEYS = ['date', 'tradedate']; @@ -28,7 +29,6 @@ export class ImportActivitiesService { 'unitprice', 'value' ]; - private static COMMENT_KEYS = ["comment", "note"] public constructor(private http: HttpClient) {} @@ -53,6 +53,7 @@ export class ImportActivitiesService { for (const [index, item] of content.entries()) { activities.push({ accountId: this.parseAccount({ item, userAccounts }), + comment: this.parseComment({ item }), currency: this.parseCurrency({ content, index, item }), dataSource: this.parseDataSource({ item }), date: this.parseDate({ content, index, item }), @@ -61,8 +62,7 @@ export class ImportActivitiesService { symbol: this.parseSymbol({ content, index, item }), type: this.parseType({ content, index, item }), unitPrice: this.parseUnitPrice({ content, index, item }), - updateAccountBalance: false, - comment: this.parseComment({ item }) + updateAccountBalance: false }); } @@ -124,17 +124,18 @@ export class ImportActivitiesService { private convertToCreateOrderDto({ accountId, + comment, date, fee, quantity, SymbolProfile, type, unitPrice, - updateAccountBalance, - comment + updateAccountBalance }: Activity): CreateOrderDto { return { accountId, + comment, fee, quantity, type, @@ -143,8 +144,7 @@ export class ImportActivitiesService { currency: SymbolProfile.currency, dataSource: SymbolProfile.dataSource, date: date.toString(), - symbol: SymbolProfile.symbol, - comment + symbol: SymbolProfile.symbol }; } @@ -178,43 +178,43 @@ export class ImportActivitiesService { return undefined; } - private parseCurrency({ - content, - index, + private parseComment({ item }: { - content: any[]; - index: number; item: any; }) { item = this.lowercaseKeys(item); - for (const key of ImportActivitiesService.CURRENCY_KEYS) { + for (const key of ImportActivitiesService.COMMENT_KEYS) { if (item[key]) { return item[key]; } } - throw { - activities: content, - message: `activities.${index}.currency is not valid` - }; + return "" } - private parseComment({ + private parseCurrency({ + content, + index, item }: { + content: any[]; + index: number; item: any; }) { item = this.lowercaseKeys(item); - for (const key of ImportActivitiesService.COMMENT_KEYS) { + for (const key of ImportActivitiesService.CURRENCY_KEYS) { if (item[key]) { return item[key]; } } - return "" + throw { + activities: content, + message: `activities.${index}.currency is not valid` + }; } private parseDataSource({ item }: { item: any }) { @@ -230,7 +230,7 @@ export class ImportActivitiesService { } private parseDate({ - content, + content, index, item }: { diff --git a/test/import/ok.csv b/test/import/ok.csv index bb2e82742..bec492a72 100644 --- a/test/import/ok.csv +++ b/test/import/ok.csv @@ -1,5 +1,5 @@ Date,Code,Currency,Price,Quantity,Action,Fee,Note 16-09-2021,MSFT,USD,298.580,5,buy,19.00,Test Note 1 -17/11/2021,MSFT,USD,0.62,5,dividend,0.00,Test Note 2 +17/11/2021,MSFT,USD,0.62,5,dividend,0.00 01.01.2022,Penthouse Apartment,USD,500000.0,1,item,0.00 -20500606,MSFT,USD,0.00,0,buy,0.00,Test Note 4 +20500606,MSFT,USD,0.00,0,buy,0.00