Browse Source

fix(ts): resolve type errors

pull/6683/head
KenTandrian 2 months ago
parent
commit
1e8ef4ce65
  1. 28
      apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts

28
apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts

@ -53,7 +53,7 @@ import { CreateOrUpdateAccountDialogParams } from './interfaces/interfaces';
export class GfCreateOrUpdateAccountDialogComponent { export class GfCreateOrUpdateAccountDialogComponent {
public accountForm: FormGroup; public accountForm: FormGroup;
public currencies: string[] = []; public currencies: string[] = [];
public filteredPlatforms: Observable<Platform[]>; public filteredPlatforms: Observable<Platform[]> | undefined;
public platforms: Platform[] = []; public platforms: Platform[] = [];
public constructor( public constructor(
@ -93,18 +93,18 @@ export class GfCreateOrUpdateAccountDialogComponent {
this.filteredPlatforms = this.accountForm this.filteredPlatforms = this.accountForm
.get('platformId') .get('platformId')
.valueChanges.pipe( ?.valueChanges.pipe(
startWith(''), startWith(''),
map((value) => { map((value: Platform | string) => {
const name = typeof value === 'string' ? value : value?.name; const name = typeof value === 'string' ? value : value?.name;
return name ? this.filter(name as string) : this.platforms.slice(); return name ? this.filter(name) : this.platforms.slice();
}) })
); );
}); });
} }
public autoCompleteCheck() { public autoCompleteCheck() {
const inputValue = this.accountForm.get('platformId').value; const inputValue = this.accountForm.get('platformId')?.value;
if (typeof inputValue === 'string') { if (typeof inputValue === 'string') {
const matchingEntry = this.platforms.find(({ name }) => { const matchingEntry = this.platforms.find(({ name }) => {
@ -112,7 +112,7 @@ export class GfCreateOrUpdateAccountDialogComponent {
}); });
if (matchingEntry) { if (matchingEntry) {
this.accountForm.get('platformId').setValue(matchingEntry); this.accountForm.get('platformId')?.setValue(matchingEntry);
} }
} }
} }
@ -127,13 +127,13 @@ export class GfCreateOrUpdateAccountDialogComponent {
public async onSubmit() { public async onSubmit() {
const account: CreateAccountDto | UpdateAccountDto = { const account: CreateAccountDto | UpdateAccountDto = {
balance: this.accountForm.get('balance').value, balance: this.accountForm.get('balance')?.value,
comment: this.accountForm.get('comment').value || null, comment: this.accountForm.get('comment')?.value || null,
currency: this.accountForm.get('currency').value, currency: this.accountForm.get('currency')?.value,
id: this.accountForm.get('accountId').value, id: this.accountForm.get('accountId')?.value,
isExcluded: this.accountForm.get('isExcluded').value, isExcluded: this.accountForm.get('isExcluded')?.value,
name: this.accountForm.get('name').value, name: this.accountForm.get('name')?.value,
platformId: this.accountForm.get('platformId').value?.id || null platformId: this.accountForm.get('platformId')?.value?.id || null
}; };
try { try {
@ -177,7 +177,7 @@ export class GfCreateOrUpdateAccountDialogComponent {
const filterValue = value.toLowerCase(); const filterValue = value.toLowerCase();
return this.platforms.filter(({ name }) => { return this.platforms.filter(({ name }) => {
return name.toLowerCase().startsWith(filterValue); return name?.toLowerCase().startsWith(filterValue);
}); });
} }
} }

Loading…
Cancel
Save