Browse Source

Bugfix: streamline quantity validation logic in create/update activity dialog

pull/4035/head
mohan 9 months ago
parent
commit
bdc077ea76
  1. 37
      apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts

37
apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts

@ -148,50 +148,31 @@ export class CreateOrUpdateActivityDialog implements OnDestroy {
], ],
updateAccountBalance: [false] updateAccountBalance: [false]
}); });
this.activityForm.get('quantity').valueChanges.subscribe(async () => { this.activityForm.valueChanges
.pipe(
// Slightly delay until the more specific form control value changes have
// completed
delay(300),
takeUntil(this.unsubscribeSubject)
)
.subscribe(async () => {
const activity = { quantity: this.activityForm.get('quantity').value }; const activity = { quantity: this.activityForm.get('quantity').value };
try { try {
const ignoredFields = [
'accountId',
'assetClass',
'assetSubClass',
'comment',
'currency',
'customCurrency',
'dataSource',
'date',
'fee',
'symbol',
'tags',
'type',
'unitPrice',
'updateAccountBalance'
];
if (this.mode === 'create') { if (this.mode === 'create') {
await validateObjectForForm({ await validateObjectForForm({
classDto: CreateOrderDto, classDto: CreateOrderDto,
form: this.activityForm, form: this.activityForm,
ignoreFields: ignoredFields,
object: activity object: activity
}); });
} else { } else {
await validateObjectForForm({ await validateObjectForForm({
classDto: UpdateOrderDto, classDto: UpdateOrderDto,
form: this.activityForm, form: this.activityForm,
ignoreFields: ignoredFields,
object: activity object: activity
}); });
} }
} catch (error) {} } catch (error) {}
});
this.activityForm.valueChanges
.pipe(
// Slightly delay until the more specific form control value changes have
// completed
delay(300),
takeUntil(this.unsubscribeSubject)
)
.subscribe(async () => {
let exchangeRateOfUnitPrice = 1; let exchangeRateOfUnitPrice = 1;
this.activityForm.get('feeInCustomCurrency').setErrors(null); this.activityForm.get('feeInCustomCurrency').setErrors(null);

Loading…
Cancel
Save