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