Browse Source

Fix formatting comments #2288

pull/4056/head
Brandon Wortman 9 months ago
parent
commit
a19b6256c7
  1. 33
      apps/client/src/app/services/import-activities.service.ts

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

@ -27,8 +27,8 @@ export class ImportActivitiesService {
private static SYMBOL_KEYS = ['code', 'symbol', 'ticker']; private static SYMBOL_KEYS = ['code', 'symbol', 'ticker'];
private static TYPE_KEYS = ['action', 'buy/sell', 'type']; private static TYPE_KEYS = ['action', 'buy/sell', 'type'];
private static UNIT_PRICE_KEYS = [ private static UNIT_PRICE_KEYS = [
'purchase price',
'price', 'price',
'purchase price',
'tradeprice', 'tradeprice',
'unitprice', 'unitprice',
'value' 'value'
@ -68,10 +68,10 @@ export class ImportActivitiesService {
currency: await this.parseCurrency({ content, index, item }), currency: await 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 }),
fee: this.parseFee({ content, index, item }), fee: this.parseFee({ index, item }),
quantity: this.parseQuantity({ content, index, item }), quantity: this.parseQuantity({ content, index, item }),
symbol: this.parseSymbol({ content, index, item }), symbol: this.parseSymbol({ content, index, item }),
type: this.parseType({ content, index, item }), type: this.parseType({ index, item }),
unitPrice: this.parseUnitPrice({ content, index, item }), unitPrice: this.parseUnitPrice({ content, index, item }),
updateAccountBalance: false updateAccountBalance: false
}); });
@ -220,7 +220,7 @@ export class ImportActivitiesService {
}) { }) {
item = this.lowercaseKeys(item); item = this.lowercaseKeys(item);
//Attempt to find currency in the CSV // Attempt to find currency in the CSV
for (const key of ImportActivitiesService.CURRENCY_KEYS) { for (const key of ImportActivitiesService.CURRENCY_KEYS) {
if (item[key]) { if (item[key]) {
return item[key]; return item[key];
@ -233,13 +233,14 @@ export class ImportActivitiesService {
return firstValueFrom( return firstValueFrom(
this.http.get<SymbolItem>(`/api/v1/symbol/${dataSource}/${symbol}`).pipe( this.http.get<SymbolItem>(`/api/v1/symbol/${dataSource}/${symbol}`).pipe(
map((response) => { map(({ currency }) => {
if (response?.currency) { if (currency) {
console.warn( console.warn(
`activities.${index}.currency was not provided, using ${response.currency} from symbol data` `activities.${index}.currency was not provided, using ${currency} from symbol data`
); );
return response.currency; return currency;
} }
throw { throw {
activities: content, activities: content,
message: `activities.${index}.currency is not valid` message: `activities.${index}.currency is not valid`
@ -293,14 +294,7 @@ export class ImportActivitiesService {
}; };
} }
private parseFee({ private parseFee({ index, item }: { index: number; item: any }) {
index,
item
}: {
content: any[];
index: number;
item: any;
}) {
item = this.lowercaseKeys(item); item = this.lowercaseKeys(item);
for (const key of ImportActivitiesService.FEE_KEYS) { for (const key of ImportActivitiesService.FEE_KEYS) {
@ -309,9 +303,7 @@ export class ImportActivitiesService {
} }
} }
this.warnings.push( this.warnings.push(`activities.${index}.fee is missing, defaulting to 0`);
`Activity ${index + 1}: Fee not provided, defaulting to 0`
);
return 0; return 0;
} }
@ -365,7 +357,6 @@ export class ImportActivitiesService {
index, index,
item item
}: { }: {
content: any[];
index: number; index: number;
item: any; item: any;
}): ActivityType { }): ActivityType {
@ -395,7 +386,7 @@ export class ImportActivitiesService {
} }
this.warnings.push( this.warnings.push(
`Activity ${index + 1}: Type not provided, defaulting to BUY` `activities.${index}.type is missing, defaulting to BUY`
); );
return 'BUY'; return 'BUY';
} }

Loading…
Cancel
Save