Browse Source

deprecated ITEM activity type removed

pull/5555/head
Attila Cseh 3 months ago
parent
commit
5a9f1bcc8c
  1. 54
      apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts
  2. 4
      apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html
  3. 2
      libs/ui/src/lib/i18n.ts

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

@ -52,6 +52,18 @@ import { DataService } from '../../../../services/data.service';
import { validateObjectForForm } from '../../../../util/form.util'; import { validateObjectForForm } from '../../../../util/form.util';
import { CreateOrUpdateActivityDialogParams } from './interfaces/interfaces'; import { CreateOrUpdateActivityDialogParams } from './interfaces/interfaces';
const DisplayedActivityType = {
BUY: Type.BUY,
DIVIDEND: Type.DIVIDEND,
FEE: Type.FEE,
INTEREST: Type.INTEREST,
LIABILITY: Type.LIABILITY,
SELL: Type.SELL,
VALUABLE: 'VALUABLE' as const
};
type DisplayedActivityType =
(typeof DisplayedActivityType)[keyof typeof DisplayedActivityType];
@Component({ @Component({
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: 'h-100' }, host: { class: 'h-100' },
@ -178,8 +190,10 @@ export class GfCreateOrUpdateActivityDialog implements OnDestroy {
}; };
}) ?? []; }) ?? [];
Object.keys(Type).forEach((type) => { Object.keys(DisplayedActivityType).forEach((type) => {
this.typesTranslationMap[Type[type]] = translate(Type[type]); this.typesTranslationMap[DisplayedActivityType[type]] = translate(
DisplayedActivityType[type]
);
}); });
this.activityForm = this.formBuilder.group({ this.activityForm = this.formBuilder.group({
@ -242,7 +256,9 @@ export class GfCreateOrUpdateActivityDialog implements OnDestroy {
) )
.subscribe(async () => { .subscribe(async () => {
if ( if (
['BUY', 'FEE', 'ITEM'].includes(this.activityForm.get('type').value) ['BUY', 'FEE', 'VALUABLE'].includes(
this.activityForm.get('type').value
)
) { ) {
this.total = this.total =
this.activityForm.get('quantity').value * this.activityForm.get('quantity').value *
@ -261,7 +277,7 @@ export class GfCreateOrUpdateActivityDialog implements OnDestroy {
this.activityForm.get('accountId').valueChanges.subscribe((accountId) => { this.activityForm.get('accountId').valueChanges.subscribe((accountId) => {
const type = this.activityForm.get('type').value; const type = this.activityForm.get('type').value;
if (['FEE', 'INTEREST', 'ITEM', 'LIABILITY'].includes(type)) { if (['FEE', 'INTEREST', 'VALUABLE', 'LIABILITY'].includes(type)) {
const currency = const currency =
this.data.accounts.find(({ id }) => { this.data.accounts.find(({ id }) => {
return id === accountId; return id === accountId;
@ -357,9 +373,9 @@ export class GfCreateOrUpdateActivityDialog implements OnDestroy {
this.activityForm this.activityForm
.get('type') .get('type')
.valueChanges.pipe(takeUntil(this.unsubscribeSubject)) .valueChanges.pipe(takeUntil(this.unsubscribeSubject))
.subscribe((type: Type) => { .subscribe((type: DisplayedActivityType) => {
if ( if (
type === 'ITEM' || type === 'VALUABLE' ||
(this.activityForm.get('dataSource').value === 'MANUAL' && (this.activityForm.get('dataSource').value === 'MANUAL' &&
type === 'BUY') type === 'BUY')
) { ) {
@ -384,7 +400,7 @@ export class GfCreateOrUpdateActivityDialog implements OnDestroy {
this.activityForm.get('name').setValidators(Validators.required); this.activityForm.get('name').setValidators(Validators.required);
this.activityForm.get('name').updateValueAndValidity(); this.activityForm.get('name').updateValueAndValidity();
if (type === 'ITEM') { if (type === 'VALUABLE') {
this.activityForm.get('quantity').setValue(1); this.activityForm.get('quantity').setValue(1);
} }
@ -513,11 +529,14 @@ export class GfCreateOrUpdateActivityDialog implements OnDestroy {
currency: this.activityForm.get('currency').value, currency: this.activityForm.get('currency').value,
customCurrency: this.activityForm.get('currencyOfUnitPrice').value, customCurrency: this.activityForm.get('currencyOfUnitPrice').value,
date: this.activityForm.get('date').value, date: this.activityForm.get('date').value,
dataSource: this.activityForm.get('dataSource').value, dataSource:
this.activityForm.get('type').value === 'VALUABLE'
? 'MANUAL'
: this.activityForm.get('dataSource').value,
fee: this.activityForm.get('fee').value, fee: this.activityForm.get('fee').value,
quantity: this.activityForm.get('quantity').value, quantity: this.activityForm.get('quantity').value,
symbol: symbol:
(['FEE', 'INTEREST', 'ITEM', 'LIABILITY'].includes( (['FEE', 'INTEREST', 'VALUABLE', 'LIABILITY'].includes(
this.activityForm.get('type').value this.activityForm.get('type').value
) )
? undefined ? undefined
@ -526,7 +545,10 @@ export class GfCreateOrUpdateActivityDialog implements OnDestroy {
tags: this.activityForm.get('tags').value?.map(({ id }) => { tags: this.activityForm.get('tags').value?.map(({ id }) => {
return id; return id;
}), }),
type: this.activityForm.get('type').value, type:
this.activityForm.get('type').value === 'VALUABLE'
? 'BUY'
: this.activityForm.get('type').value,
unitPrice: this.activityForm.get('unitPrice').value unitPrice: this.activityForm.get('unitPrice').value
}; };
@ -543,12 +565,6 @@ export class GfCreateOrUpdateActivityDialog implements OnDestroy {
object: activity object: activity
}); });
if (activity.type === 'ITEM') {
// Transform deprecated type ITEM
activity.dataSource = 'MANUAL';
activity.type = 'BUY';
}
this.dialogRef.close(activity); this.dialogRef.close(activity);
} else { } else {
(activity as UpdateOrderDto).id = this.data.activity?.id; (activity as UpdateOrderDto).id = this.data.activity?.id;
@ -560,12 +576,6 @@ export class GfCreateOrUpdateActivityDialog implements OnDestroy {
object: activity as UpdateOrderDto object: activity as UpdateOrderDto
}); });
if (activity.type === 'ITEM') {
// Transform deprecated type ITEM
activity.dataSource = 'MANUAL';
activity.type = 'BUY';
}
this.dialogRef.close(activity as UpdateOrderDto); this.dialogRef.close(activity as UpdateOrderDto);
} }
} catch (error) { } catch (error) {

4
apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html

@ -65,9 +65,9 @@
>Stocks, ETFs, bonds, cryptocurrencies, commodities</small >Stocks, ETFs, bonds, cryptocurrencies, commodities</small
> >
</mat-option> </mat-option>
<mat-option value="ITEM"> <mat-option value="VALUABLE">
<span <span
><b>{{ typesTranslationMap['ITEM'] }}</b></span ><b>{{ typesTranslationMap['VALUABLE'] }}</b></span
> >
<small class="d-block line-height-1 text-muted text-nowrap" i18n <small class="d-block line-height-1 text-muted text-nowrap" i18n
>Luxury items, real estate, private companies</small >Luxury items, real estate, private companies</small

2
libs/ui/src/lib/i18n.ts

@ -38,7 +38,7 @@ const locales = {
DIVIDEND: $localize`Dividend`, DIVIDEND: $localize`Dividend`,
FEE: $localize`Fee`, FEE: $localize`Fee`,
INTEREST: $localize`Interest`, INTEREST: $localize`Interest`,
ITEM: $localize`Valuable`, VALUABLE: $localize`Valuable`,
LIABILITY: $localize`Liability`, LIABILITY: $localize`Liability`,
SELL: $localize`Sell`, SELL: $localize`Sell`,

Loading…
Cancel
Save