Browse Source

Added all the recommended changes

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

42
apps/client/src/app/services/import-activities.service.ts

@ -15,6 +15,7 @@ import { catchError } from 'rxjs/operators';
}) })
export class ImportActivitiesService { export class ImportActivitiesService {
private static ACCOUNT_KEYS = ['account', 'accountid']; private static ACCOUNT_KEYS = ['account', 'accountid'];
private static COMMENT_KEYS = ["comment", "note"]
private static CURRENCY_KEYS = ['ccy', 'currency', 'currencyprimary']; private static CURRENCY_KEYS = ['ccy', 'currency', 'currencyprimary'];
private static DATA_SOURCE_KEYS = ['datasource']; private static DATA_SOURCE_KEYS = ['datasource'];
private static DATE_KEYS = ['date', 'tradedate']; private static DATE_KEYS = ['date', 'tradedate'];
@ -28,7 +29,6 @@ export class ImportActivitiesService {
'unitprice', 'unitprice',
'value' 'value'
]; ];
private static COMMENT_KEYS = ["comment", "note"]
public constructor(private http: HttpClient) {} public constructor(private http: HttpClient) {}
@ -53,6 +53,7 @@ export class ImportActivitiesService {
for (const [index, item] of content.entries()) { for (const [index, item] of content.entries()) {
activities.push({ activities.push({
accountId: this.parseAccount({ item, userAccounts }), accountId: this.parseAccount({ item, userAccounts }),
comment: this.parseComment({ item }),
currency: this.parseCurrency({ content, index, item }), currency: this.parseCurrency({ content, index, item }),
dataSource: this.parseDataSource({ item }), dataSource: this.parseDataSource({ item }),
date: this.parseDate({ content, index, item }), date: this.parseDate({ content, index, item }),
@ -61,8 +62,7 @@ export class ImportActivitiesService {
symbol: this.parseSymbol({ content, index, item }), symbol: this.parseSymbol({ content, index, item }),
type: this.parseType({ content, index, item }), type: this.parseType({ content, index, item }),
unitPrice: this.parseUnitPrice({ content, index, item }), unitPrice: this.parseUnitPrice({ content, index, item }),
updateAccountBalance: false, updateAccountBalance: false
comment: this.parseComment({ item })
}); });
} }
@ -124,17 +124,18 @@ export class ImportActivitiesService {
private convertToCreateOrderDto({ private convertToCreateOrderDto({
accountId, accountId,
comment,
date, date,
fee, fee,
quantity, quantity,
SymbolProfile, SymbolProfile,
type, type,
unitPrice, unitPrice,
updateAccountBalance, updateAccountBalance
comment
}: Activity): CreateOrderDto { }: Activity): CreateOrderDto {
return { return {
accountId, accountId,
comment,
fee, fee,
quantity, quantity,
type, type,
@ -143,8 +144,7 @@ export class ImportActivitiesService {
currency: SymbolProfile.currency, currency: SymbolProfile.currency,
dataSource: SymbolProfile.dataSource, dataSource: SymbolProfile.dataSource,
date: date.toString(), date: date.toString(),
symbol: SymbolProfile.symbol, symbol: SymbolProfile.symbol
comment
}; };
} }
@ -178,43 +178,43 @@ export class ImportActivitiesService {
return undefined; return undefined;
} }
private parseCurrency({ private parseComment({
content,
index,
item item
}: { }: {
content: any[];
index: number;
item: any; item: any;
}) { }) {
item = this.lowercaseKeys(item); item = this.lowercaseKeys(item);
for (const key of ImportActivitiesService.CURRENCY_KEYS) { for (const key of ImportActivitiesService.COMMENT_KEYS) {
if (item[key]) { if (item[key]) {
return item[key]; return item[key];
} }
} }
throw { return ""
activities: content,
message: `activities.${index}.currency is not valid`
};
} }
private parseComment({ private parseCurrency({
content,
index,
item item
}: { }: {
content: any[];
index: number;
item: any; item: any;
}) { }) {
item = this.lowercaseKeys(item); item = this.lowercaseKeys(item);
for (const key of ImportActivitiesService.COMMENT_KEYS) { for (const key of ImportActivitiesService.CURRENCY_KEYS) {
if (item[key]) { if (item[key]) {
return item[key]; return item[key];
} }
} }
return "" throw {
activities: content,
message: `activities.${index}.currency is not valid`
};
} }
private parseDataSource({ item }: { item: any }) { private parseDataSource({ item }: { item: any }) {
@ -230,7 +230,7 @@ export class ImportActivitiesService {
} }
private parseDate({ private parseDate({
content, content,
index, index,
item item
}: { }: {

4
test/import/ok.csv

@ -1,5 +1,5 @@
Date,Code,Currency,Price,Quantity,Action,Fee,Note Date,Code,Currency,Price,Quantity,Action,Fee,Note
16-09-2021,MSFT,USD,298.580,5,buy,19.00,Test Note 1 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 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