Browse Source

Added Comment support via csv import

pull/2416/head
Arshad Jamal 2 years ago
parent
commit
65689dcac6
  1. 26
      apps/client/src/app/services/import-activities.service.ts
  2. 8
      test/import/ok.csv

26
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);

8
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

Can't render this file because it has a wrong number of fields in line 4.
Loading…
Cancel
Save