diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts b/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts index 26fe9f14a62bfb70ba23927fded324682995ac62..d8071b1434a873de385f57eceb81b720a4e06eec 100644 --- a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts +++ b/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts @@ -1,4 +1,9 @@ -import { AbstractFormService, HttpError, StateResource } from '@alfa-client/tech-shared'; +import { + AbstractFormService, + EMPTY_STRING, + HttpError, + StateResource, +} from '@alfa-client/tech-shared'; import { Injectable } from '@angular/core'; import { FormControl, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; import { Observable } from 'rxjs'; @@ -27,13 +32,13 @@ export class PostfachFormService extends AbstractFormService { protected initForm(): UntypedFormGroup { return this.formBuilder.group({ [PostfachFormService.ASBSENDER_GROUP]: this.formBuilder.group({ - [PostfachFormService.NAME_FIELD]: new FormControl(''), - [PostfachFormService.ANSCHRIFT_FIELD]: new FormControl(''), - [PostfachFormService.DIENST_FIELD]: new FormControl(''), - [PostfachFormService.MANDANT_FIELD]: new FormControl(''), - [PostfachFormService.GEMEINDESCHLUESSEL_FIELD]: new FormControl(''), + [PostfachFormService.NAME_FIELD]: new FormControl(EMPTY_STRING), + [PostfachFormService.ANSCHRIFT_FIELD]: new FormControl(EMPTY_STRING), + [PostfachFormService.DIENST_FIELD]: new FormControl(EMPTY_STRING), + [PostfachFormService.MANDANT_FIELD]: new FormControl(EMPTY_STRING), + [PostfachFormService.GEMEINDESCHLUESSEL_FIELD]: new FormControl(EMPTY_STRING), }), - [PostfachFormService.SIGNATUR_FIELD]: new FormControl(''), + [PostfachFormService.SIGNATUR_FIELD]: new FormControl(EMPTY_STRING), }); } diff --git a/alfa-client/libs/tech-shared/src/lib/error/error.util.ts b/alfa-client/libs/tech-shared/src/lib/error/error.util.ts index c6029db8c9e7534811804cf9ed2e3ce929997b73..81c2a8d62e817d5e4907c194bf9dd62bfa2fd3a1 100644 --- a/alfa-client/libs/tech-shared/src/lib/error/error.util.ts +++ b/alfa-client/libs/tech-shared/src/lib/error/error.util.ts @@ -22,8 +22,9 @@ * unter der Lizenz sind dem Lizenztext zu entnehmen. */ import { HttpErrorResponse } from '@angular/common/http'; -import { ApiError, MessageCode } from '@alfa-client/tech-shared'; import { isNil } from 'lodash-es'; +import { MessageCode } from '../message-code'; +import { ApiError, HttpError } from '../tech.model'; export function isApiError(value: any): boolean { return !isNil(value?.issues) && !isNil(value.issues[0]); diff --git a/alfa-client/libs/tech-shared/src/lib/validation/tech.validation.util.spec.ts b/alfa-client/libs/tech-shared/src/lib/validation/tech.validation.util.spec.ts index 658c577bd6ab2d7213a6288657c47e0a0aeef500..9e0902270b2423a9510872b1a5f15828549eb8d6 100644 --- a/alfa-client/libs/tech-shared/src/lib/validation/tech.validation.util.spec.ts +++ b/alfa-client/libs/tech-shared/src/lib/validation/tech.validation.util.spec.ts @@ -21,7 +21,13 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -import { AbstractControl, FormControl, FormGroup, UntypedFormControl, UntypedFormGroup } from '@angular/forms'; +import { + AbstractControl, + FormControl, + FormGroup, + UntypedFormControl, + UntypedFormGroup, +} from '@angular/forms'; import { createInvalidParam, createIssue } from '../../../test/error'; import { InvalidParam, Issue } from '../tech.model'; import { @@ -145,9 +151,9 @@ describe('ValidationUtils', () => { }); describe('invalid param', () => { - const formPrefixes = ['', 'some-prefix']; - const fieldNames = ['baseField1', 'baseField2', 'subGroup.subGroupField1']; - const prefixNameCombinations = formPrefixes.flatMap((prefix) => + const formPrefixes: string[] = ['', 'some-prefix']; + const fieldNames: string[] = ['baseField1', 'baseField2', 'subGroup.subGroupField1']; + const prefixNameCombinations: string[][] = formPrefixes.flatMap((prefix) => fieldNames.map((name) => [prefix, name]), ); const unknownName = 'unknown-field'; @@ -183,11 +189,11 @@ describe('ValidationUtils', () => { describe('set invalid param validation error', () => { it('should assign invalidParam to form control error without prefix', () => { - const message = getMessageForInvalidParam(invalidParam, prefix); + const message: string = getMessageForInvalidParam(invalidParam, prefix); setInvalidParamValidationError(form, invalidParam, prefix); - const errorMessage = form.getError(invalidParam.reason, fieldName); + const errorMessage: string = form.getError(invalidParam.reason, fieldName); expect(errorMessage).toBe(message); }); diff --git a/alfa-client/libs/tech-shared/src/lib/validation/tech.validation.util.ts b/alfa-client/libs/tech-shared/src/lib/validation/tech.validation.util.ts index a42904b4cc50a322b0345f71df54f4c7824da733..4a34005de2f231027678dc6ce606a8cc2e3e1bed 100644 --- a/alfa-client/libs/tech-shared/src/lib/validation/tech.validation.util.ts +++ b/alfa-client/libs/tech-shared/src/lib/validation/tech.validation.util.ts @@ -83,7 +83,7 @@ export function getMessageCode(apiError: ApiError): string { export function setInvalidParamValidationError( form: UntypedFormGroup, invalidParam: InvalidParam, - pathPrefix: string = '', + pathPrefix?: string, ): void { const control: AbstractControl = getControlForInvalidParam(form, invalidParam, pathPrefix); if (isNotNil(control)) { @@ -94,14 +94,10 @@ export function setInvalidParamValidationError( } } -function getFieldPathWithoutPrefix(name: string, pathPrefix: string): string { - return pathPrefix.length > 0 ? name.substring(pathPrefix.length + 1) : name; -} - export function getControlForInvalidParam( form: UntypedFormGroup, invalidParam: InvalidParam, - pathPrefix: string = '', + pathPrefix?: string, ): AbstractControl { return form.get(getFieldPathWithoutPrefix(invalidParam.name, pathPrefix)); } @@ -113,3 +109,7 @@ export function getMessageForInvalidParam(item: InvalidParam, pathPrefix: string getFieldPathWithoutPrefix(item.name, pathPrefix), ); } + +function getFieldPathWithoutPrefix(name: string, pathPrefix?: string): string { + return pathPrefix ? name.substring(pathPrefix.length + 1) : name; +} diff --git a/alfa-client/libs/ui/src/lib/ui/editor/formcontrol-editor.abstract.component.ts b/alfa-client/libs/ui/src/lib/ui/editor/formcontrol-editor.abstract.component.ts index 345cf7de9e8bc26499a742b344023b7b0ec018d2..517a4a67c60e32e79a882f4c84e2c9e4565e333b 100644 --- a/alfa-client/libs/ui/src/lib/ui/editor/formcontrol-editor.abstract.component.ts +++ b/alfa-client/libs/ui/src/lib/ui/editor/formcontrol-editor.abstract.component.ts @@ -80,7 +80,7 @@ export abstract class FormControlEditorAbstractComponent implements ControlValue if (this.statusSubscr) this.statusSubscr.unsubscribe(); } - setErrors() { + setErrors(): void { if (this.control) { this.fieldControl.setErrors(this.control.errors); if (this.control.invalid) this.fieldControl.markAsTouched(); diff --git a/alfa-client/libs/user-profile/src/lib/user-icon/user-icon.component.ts b/alfa-client/libs/user-profile/src/lib/user-icon/user-icon.component.ts index 82976c7be94d3b9cec56f1b68079815d2cbf9352..78547141a5665a15799b97afc211cee0134f8d49 100644 --- a/alfa-client/libs/user-profile/src/lib/user-icon/user-icon.component.ts +++ b/alfa-client/libs/user-profile/src/lib/user-icon/user-icon.component.ts @@ -22,7 +22,13 @@ * unter der Lizenz sind dem Lizenztext zu entnehmen. */ import { Component, Input, SimpleChanges } from '@angular/core'; -import { createEmptyStateResource, hasError, MessageCode, StateResource } from '@alfa-client/tech-shared'; +import { + ApiError, + createEmptyStateResource, + hasError, + MessageCode, + StateResource, +} from '@alfa-client/tech-shared'; import { getUserName, getUserNameInitials, @@ -71,7 +77,7 @@ export class UserIconComponent { } get errorMessageCode(): string { - return this.userProfileStateResource.error?.issues[0]?.messageCode; + return (<ApiError>this.userProfileStateResource.error)?.issues[0]?.messageCode; } get initials(): string { diff --git a/alfa-client/libs/user-profile/src/lib/user-profile-in-vorgang-container/user-profile-in-vorgang/user-profile-in-vorgang.component.ts b/alfa-client/libs/user-profile/src/lib/user-profile-in-vorgang-container/user-profile-in-vorgang/user-profile-in-vorgang.component.ts index a255e3a75afd20a9085cae37f92e405d00fc0fd8..4a93a23e00e7211c40a49c585acd73d78bba2ed7 100644 --- a/alfa-client/libs/user-profile/src/lib/user-profile-in-vorgang-container/user-profile-in-vorgang/user-profile-in-vorgang.component.ts +++ b/alfa-client/libs/user-profile/src/lib/user-profile-in-vorgang-container/user-profile-in-vorgang/user-profile-in-vorgang.component.ts @@ -23,6 +23,7 @@ */ import { Component, Input } from '@angular/core'; import { + ApiError, StateResource, createEmptyStateResource, hasError, @@ -45,7 +46,7 @@ export class UserProfileInVorgangComponent { readonly vorgangLinkRel = VorgangWithEingangLinkRel; public isUserServiceAvailable(stateResource: StateResource<Resource>): boolean { - if (hasError(stateResource) && isServiceUnavailableMessageCode(stateResource.error)) { + if (hasError(stateResource) && isServiceUnavailableMessageCode(<ApiError>stateResource.error)) { return false; } return true;