|
|
@ -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 |
|
|
|
}: { |
|
|
|