diff --git a/apps/client/src/app/services/import-activities.service.ts b/apps/client/src/app/services/import-activities.service.ts index 808081bea..f843ac43b 100644 --- a/apps/client/src/app/services/import-activities.service.ts +++ b/apps/client/src/app/services/import-activities.service.ts @@ -28,6 +28,7 @@ export class ImportActivitiesService { 'unitprice', 'value' ]; + private static COMMENT_KEYS = ["comment", "note"] public constructor(private http: HttpClient) {} @@ -60,7 +61,8 @@ export class ImportActivitiesService { symbol: this.parseSymbol({ content, index, item }), type: this.parseType({ content, index, item }), unitPrice: this.parseUnitPrice({ content, index, item }), - updateAccountBalance: false + updateAccountBalance: false, + comment: this.parseComment({ item }) }); } @@ -128,7 +130,8 @@ export class ImportActivitiesService { SymbolProfile, type, unitPrice, - updateAccountBalance + updateAccountBalance, + comment }: Activity): CreateOrderDto { return { accountId, @@ -140,7 +143,8 @@ export class ImportActivitiesService { currency: SymbolProfile.currency, dataSource: SymbolProfile.dataSource, date: date.toString(), - symbol: SymbolProfile.symbol + symbol: SymbolProfile.symbol, + comment }; } @@ -197,6 +201,22 @@ export class ImportActivitiesService { }; } + private parseComment({ + item + }: { + item: any; + }) { + item = this.lowercaseKeys(item); + + for (const key of ImportActivitiesService.COMMENT_KEYS) { + if (item[key]) { + return item[key]; + } + } + + return "" + } + private parseDataSource({ item }: { item: any }) { item = this.lowercaseKeys(item); @@ -210,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 732ab4699..bb2e82742 100644 --- a/test/import/ok.csv +++ b/test/import/ok.csv @@ -1,5 +1,5 @@ -Date,Code,Currency,Price,Quantity,Action,Fee -16-09-2021,MSFT,USD,298.580,5,buy,19.00 -17/11/2021,MSFT,USD,0.62,5,dividend,0.00 +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 01.01.2022,Penthouse Apartment,USD,500000.0,1,item,0.00 -20500606,MSFT,USD,0.00,0,buy,0.00 +20500606,MSFT,USD,0.00,0,buy,0.00,Test Note 4