Browse Source

Improve activities import

pull/1540/head
Thomas 3 years ago
parent
commit
893765a657
  1. 4
      apps/client/src/app/pages/portfolio/activities/import-activities-dialog/import-activities-dialog.component.ts
  2. 39
      apps/client/src/app/services/import-activities.service.ts
  3. 2
      libs/ui/src/lib/activities-table/activities-table.component.html

4
apps/client/src/app/pages/portfolio/activities/import-activities-dialog/import-activities-dialog.component.ts

@ -120,7 +120,7 @@ export class ImportActivitiesDialog implements OnDestroy {
try {
this.activities = await this.importActivitiesService.importJson({
content: content.activities,
dryRun: true
isDryRun: true
});
} catch (error) {
console.error(error);
@ -131,8 +131,8 @@ export class ImportActivitiesDialog implements OnDestroy {
} else if (file.name.endsWith('.csv')) {
try {
this.activities = await this.importActivitiesService.importCsv({
dryRun: true,
fileContent,
isDryRun: true,
userAccounts: this.data.user.accounts
});
} catch (error) {

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

@ -26,12 +26,12 @@ export class ImportActivitiesService {
public constructor(private http: HttpClient) {}
public async importCsv({
dryRun = false,
fileContent,
isDryRun = false,
userAccounts
}: {
dryRun?: boolean;
fileContent: string;
isDryRun?: boolean;
userAccounts: Account[];
}): Promise<Activity[]> {
const content = csvToJson(fileContent, {
@ -55,22 +55,22 @@ export class ImportActivitiesService {
});
}
return await this.importJson({ content: activities, dryRun });
return await this.importJson({ isDryRun, content: activities });
}
public importJson({
content,
dryRun = false
isDryRun = false
}: {
content: CreateOrderDto[];
dryRun?: boolean;
isDryRun?: boolean;
}): Promise<Activity[]> {
return new Promise((resolve, reject) => {
this.postImport(
{
activities: content
},
dryRun
isDryRun
)
.pipe(
catchError((error) => {
@ -96,15 +96,22 @@ export class ImportActivitiesService {
return this.importJson({ content: importData });
}
private convertToCreateOrderDto(aActivity: Activity): CreateOrderDto {
private convertToCreateOrderDto({
date,
fee,
quantity,
SymbolProfile,
type,
unitPrice
}: Activity): CreateOrderDto {
return {
currency: aActivity.SymbolProfile.currency,
date: aActivity.date.toString(),
fee: aActivity.fee,
quantity: aActivity.quantity,
symbol: aActivity.SymbolProfile.symbol,
type: aActivity.type,
unitPrice: aActivity.unitPrice
fee,
quantity,
type,
unitPrice,
currency: SymbolProfile.currency,
date: date.toString(),
symbol: SymbolProfile.symbol
};
}
@ -337,10 +344,10 @@ export class ImportActivitiesService {
private postImport(
aImportData: { activities: CreateOrderDto[] },
dryRun = false
aIsDryRun = false
) {
return this.http.post<{ activities: Activity[] }>(
`/api/v1/import?dryRun=${dryRun}`,
`/api/v1/import?dryRun=${aIsDryRun}`,
aImportData
);
}

2
libs/ui/src/lib/activities-table/activities-table.component.html

@ -19,6 +19,7 @@
<th *matHeaderCellDef class="px-1" mat-header-cell>
<mat-checkbox
class="mt-2"
color="primary"
[checked]="selectedRows.hasValue() && areAllRowsSelected()"
[indeterminate]="selectedRows.hasValue() && !areAllRowsSelected()"
(change)="$event ? toggleAllRows() : null"
@ -27,6 +28,7 @@
<td *matCellDef="let element" class="px-1" mat-cell>
<mat-checkbox
class="mt-2"
color="primary"
[checked]="selectedRows.isSelected(element)"
(change)="$event ? selectedRows.toggle(element) : null"
(click)="$event.stopPropagation()"

Loading…
Cancel
Save