Feature/rename orders to activities in import and export (#786)
* Rename orders to activities * Update changelog
This commit is contained in:
@@ -27,12 +27,12 @@ export class ImportTransactionDialog implements OnDestroy {
|
||||
|
||||
public ngOnInit() {
|
||||
for (const message of this.data.messages) {
|
||||
if (message.includes('orders.')) {
|
||||
if (message.includes('activities.')) {
|
||||
let [index] = message.split(' ');
|
||||
index = index.replace('orders.', '');
|
||||
index = index.replace('activities.', '');
|
||||
[index] = index.split('.');
|
||||
|
||||
this.details.push(this.data.orders[index]);
|
||||
this.details.push(this.data.activities[index]);
|
||||
} else {
|
||||
this.details.push('');
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
export interface ImportTransactionDialogParams {
|
||||
activities: any[];
|
||||
deviceType: string;
|
||||
messages: string[];
|
||||
orders: any[];
|
||||
}
|
||||
|
@@ -185,19 +185,31 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
|
||||
if (file.name.endsWith('.json')) {
|
||||
const content = JSON.parse(fileContent);
|
||||
|
||||
if (!isArray(content.orders)) {
|
||||
throw new Error();
|
||||
if (!isArray(content.activities)) {
|
||||
if (isArray(content.orders)) {
|
||||
this.handleImportError({
|
||||
activities: [],
|
||||
error: {
|
||||
error: {
|
||||
message: [`orders needs to be renamed to activities`]
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await this.importTransactionsService.importJson({
|
||||
content: content.orders
|
||||
content: content.activities
|
||||
});
|
||||
|
||||
this.handleImportSuccess();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
this.handleImportError({ error, orders: content.orders });
|
||||
this.handleImportError({ error, activities: content.activities });
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -212,10 +224,10 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
this.handleImportError({
|
||||
activities: error?.activities ?? [],
|
||||
error: {
|
||||
error: { message: error?.error?.message ?? [error?.message] }
|
||||
},
|
||||
orders: error?.orders ?? []
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -226,8 +238,8 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
this.handleImportError({
|
||||
error: { error: { message: ['Unexpected format'] } },
|
||||
orders: []
|
||||
activities: [],
|
||||
error: { error: { message: ['Unexpected format'] } }
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -281,12 +293,18 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
|
||||
this.unsubscribeSubject.complete();
|
||||
}
|
||||
|
||||
private handleImportError({ error, orders }: { error: any; orders: any[] }) {
|
||||
private handleImportError({
|
||||
activities,
|
||||
error
|
||||
}: {
|
||||
activities: any[];
|
||||
error: any;
|
||||
}) {
|
||||
this.snackBar.dismiss();
|
||||
|
||||
this.dialog.open(ImportTransactionDialog, {
|
||||
data: {
|
||||
orders,
|
||||
activities,
|
||||
deviceType: this.deviceType,
|
||||
messages: error?.error?.message
|
||||
},
|
||||
|
@@ -37,9 +37,9 @@ export class ImportTransactionsService {
|
||||
skipEmptyLines: true
|
||||
}).data;
|
||||
|
||||
const orders: CreateOrderDto[] = [];
|
||||
const activities: CreateOrderDto[] = [];
|
||||
for (const [index, item] of content.entries()) {
|
||||
orders.push({
|
||||
activities.push({
|
||||
accountId: this.parseAccount({ item, userAccounts }),
|
||||
currency: this.parseCurrency({ content, index, item }),
|
||||
dataSource: this.parseDataSource({ item }),
|
||||
@@ -52,13 +52,13 @@ export class ImportTransactionsService {
|
||||
});
|
||||
}
|
||||
|
||||
await this.importJson({ content: orders });
|
||||
await this.importJson({ content: activities });
|
||||
}
|
||||
|
||||
public importJson({ content }: { content: CreateOrderDto[] }): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.postImport({
|
||||
orders: content
|
||||
activities: content
|
||||
})
|
||||
.pipe(
|
||||
catchError((error) => {
|
||||
@@ -121,7 +121,10 @@ export class ImportTransactionsService {
|
||||
}
|
||||
}
|
||||
|
||||
throw { message: `orders.${index}.currency is not valid`, orders: content };
|
||||
throw {
|
||||
activities: content,
|
||||
message: `activities.${index}.currency is not valid`
|
||||
};
|
||||
}
|
||||
|
||||
private parseDataSource({ item }: { item: any }) {
|
||||
@@ -164,7 +167,10 @@ export class ImportTransactionsService {
|
||||
}
|
||||
}
|
||||
|
||||
throw { message: `orders.${index}.date is not valid`, orders: content };
|
||||
throw {
|
||||
activities: content,
|
||||
message: `activities.${index}.date is not valid`
|
||||
};
|
||||
}
|
||||
|
||||
private parseFee({
|
||||
@@ -184,7 +190,10 @@ export class ImportTransactionsService {
|
||||
}
|
||||
}
|
||||
|
||||
throw { message: `orders.${index}.fee is not valid`, orders: content };
|
||||
throw {
|
||||
activities: content,
|
||||
message: `activities.${index}.fee is not valid`
|
||||
};
|
||||
}
|
||||
|
||||
private parseQuantity({
|
||||
@@ -204,7 +213,10 @@ export class ImportTransactionsService {
|
||||
}
|
||||
}
|
||||
|
||||
throw { message: `orders.${index}.quantity is not valid`, orders: content };
|
||||
throw {
|
||||
activities: content,
|
||||
message: `activities.${index}.quantity is not valid`
|
||||
};
|
||||
}
|
||||
|
||||
private parseSymbol({
|
||||
@@ -224,7 +236,10 @@ export class ImportTransactionsService {
|
||||
}
|
||||
}
|
||||
|
||||
throw { message: `orders.${index}.symbol is not valid`, orders: content };
|
||||
throw {
|
||||
activities: content,
|
||||
message: `activities.${index}.symbol is not valid`
|
||||
};
|
||||
}
|
||||
|
||||
private parseType({
|
||||
@@ -255,7 +270,10 @@ export class ImportTransactionsService {
|
||||
}
|
||||
}
|
||||
|
||||
throw { message: `orders.${index}.type is not valid`, orders: content };
|
||||
throw {
|
||||
activities: content,
|
||||
message: `activities.${index}.type is not valid`
|
||||
};
|
||||
}
|
||||
|
||||
private parseUnitPrice({
|
||||
@@ -276,12 +294,12 @@ export class ImportTransactionsService {
|
||||
}
|
||||
|
||||
throw {
|
||||
message: `orders.${index}.unitPrice is not valid`,
|
||||
orders: content
|
||||
activities: content,
|
||||
message: `activities.${index}.unitPrice is not valid`
|
||||
};
|
||||
}
|
||||
|
||||
private postImport(aImportData: { orders: CreateOrderDto[] }) {
|
||||
private postImport(aImportData: { activities: CreateOrderDto[] }) {
|
||||
return this.http.post<void>('/api/v1/import', aImportData);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user