Browse Source

Added all the recommended changes

pull/2416/head
Arshad Jamal 2 years ago
parent
commit
88b8a69157
  1. 40
      apps/client/src/app/services/import-activities.service.ts
  2. 4
      test/import/ok.csv

40
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 }) {

4
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

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