Skip to content
Snippets Groups Projects
Commit bd5a7588 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4949 fix casts; add types; reorder functions; fix import

parent 14b641f5
No related branches found
No related tags found
No related merge requests found
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 { Injectable } from '@angular/core';
import { FormControl, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; import { FormControl, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
...@@ -27,13 +32,13 @@ export class PostfachFormService extends AbstractFormService { ...@@ -27,13 +32,13 @@ export class PostfachFormService extends AbstractFormService {
protected initForm(): UntypedFormGroup { protected initForm(): UntypedFormGroup {
return this.formBuilder.group({ return this.formBuilder.group({
[PostfachFormService.ASBSENDER_GROUP]: this.formBuilder.group({ [PostfachFormService.ASBSENDER_GROUP]: this.formBuilder.group({
[PostfachFormService.NAME_FIELD]: new FormControl(''), [PostfachFormService.NAME_FIELD]: new FormControl(EMPTY_STRING),
[PostfachFormService.ANSCHRIFT_FIELD]: new FormControl(''), [PostfachFormService.ANSCHRIFT_FIELD]: new FormControl(EMPTY_STRING),
[PostfachFormService.DIENST_FIELD]: new FormControl(''), [PostfachFormService.DIENST_FIELD]: new FormControl(EMPTY_STRING),
[PostfachFormService.MANDANT_FIELD]: new FormControl(''), [PostfachFormService.MANDANT_FIELD]: new FormControl(EMPTY_STRING),
[PostfachFormService.GEMEINDESCHLUESSEL_FIELD]: new FormControl(''), [PostfachFormService.GEMEINDESCHLUESSEL_FIELD]: new FormControl(EMPTY_STRING),
}), }),
[PostfachFormService.SIGNATUR_FIELD]: new FormControl(''), [PostfachFormService.SIGNATUR_FIELD]: new FormControl(EMPTY_STRING),
}); });
} }
......
...@@ -22,8 +22,9 @@ ...@@ -22,8 +22,9 @@
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
import { HttpErrorResponse } from '@angular/common/http'; import { HttpErrorResponse } from '@angular/common/http';
import { ApiError, MessageCode } from '@alfa-client/tech-shared';
import { isNil } from 'lodash-es'; import { isNil } from 'lodash-es';
import { MessageCode } from '../message-code';
import { ApiError, HttpError } from '../tech.model';
export function isApiError(value: any): boolean { export function isApiError(value: any): boolean {
return !isNil(value?.issues) && !isNil(value.issues[0]); return !isNil(value?.issues) && !isNil(value.issues[0]);
......
...@@ -21,7 +21,13 @@ ...@@ -21,7 +21,13 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen * Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen. * 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 { createInvalidParam, createIssue } from '../../../test/error';
import { InvalidParam, Issue } from '../tech.model'; import { InvalidParam, Issue } from '../tech.model';
import { import {
...@@ -145,9 +151,9 @@ describe('ValidationUtils', () => { ...@@ -145,9 +151,9 @@ describe('ValidationUtils', () => {
}); });
describe('invalid param', () => { describe('invalid param', () => {
const formPrefixes = ['', 'some-prefix']; const formPrefixes: string[] = ['', 'some-prefix'];
const fieldNames = ['baseField1', 'baseField2', 'subGroup.subGroupField1']; const fieldNames: string[] = ['baseField1', 'baseField2', 'subGroup.subGroupField1'];
const prefixNameCombinations = formPrefixes.flatMap((prefix) => const prefixNameCombinations: string[][] = formPrefixes.flatMap((prefix) =>
fieldNames.map((name) => [prefix, name]), fieldNames.map((name) => [prefix, name]),
); );
const unknownName = 'unknown-field'; const unknownName = 'unknown-field';
...@@ -183,11 +189,11 @@ describe('ValidationUtils', () => { ...@@ -183,11 +189,11 @@ describe('ValidationUtils', () => {
describe('set invalid param validation error', () => { describe('set invalid param validation error', () => {
it('should assign invalidParam to form control error without prefix', () => { 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); setInvalidParamValidationError(form, invalidParam, prefix);
const errorMessage = form.getError(invalidParam.reason, fieldName); const errorMessage: string = form.getError(invalidParam.reason, fieldName);
expect(errorMessage).toBe(message); expect(errorMessage).toBe(message);
}); });
......
...@@ -83,7 +83,7 @@ export function getMessageCode(apiError: ApiError): string { ...@@ -83,7 +83,7 @@ export function getMessageCode(apiError: ApiError): string {
export function setInvalidParamValidationError( export function setInvalidParamValidationError(
form: UntypedFormGroup, form: UntypedFormGroup,
invalidParam: InvalidParam, invalidParam: InvalidParam,
pathPrefix: string = '', pathPrefix?: string,
): void { ): void {
const control: AbstractControl = getControlForInvalidParam(form, invalidParam, pathPrefix); const control: AbstractControl = getControlForInvalidParam(form, invalidParam, pathPrefix);
if (isNotNil(control)) { if (isNotNil(control)) {
...@@ -94,14 +94,10 @@ export function setInvalidParamValidationError( ...@@ -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( export function getControlForInvalidParam(
form: UntypedFormGroup, form: UntypedFormGroup,
invalidParam: InvalidParam, invalidParam: InvalidParam,
pathPrefix: string = '', pathPrefix?: string,
): AbstractControl { ): AbstractControl {
return form.get(getFieldPathWithoutPrefix(invalidParam.name, pathPrefix)); return form.get(getFieldPathWithoutPrefix(invalidParam.name, pathPrefix));
} }
...@@ -113,3 +109,7 @@ export function getMessageForInvalidParam(item: InvalidParam, pathPrefix: string ...@@ -113,3 +109,7 @@ export function getMessageForInvalidParam(item: InvalidParam, pathPrefix: string
getFieldPathWithoutPrefix(item.name, pathPrefix), getFieldPathWithoutPrefix(item.name, pathPrefix),
); );
} }
function getFieldPathWithoutPrefix(name: string, pathPrefix?: string): string {
return pathPrefix ? name.substring(pathPrefix.length + 1) : name;
}
...@@ -80,7 +80,7 @@ export abstract class FormControlEditorAbstractComponent implements ControlValue ...@@ -80,7 +80,7 @@ export abstract class FormControlEditorAbstractComponent implements ControlValue
if (this.statusSubscr) this.statusSubscr.unsubscribe(); if (this.statusSubscr) this.statusSubscr.unsubscribe();
} }
setErrors() { setErrors(): void {
if (this.control) { if (this.control) {
this.fieldControl.setErrors(this.control.errors); this.fieldControl.setErrors(this.control.errors);
if (this.control.invalid) this.fieldControl.markAsTouched(); if (this.control.invalid) this.fieldControl.markAsTouched();
......
...@@ -22,7 +22,13 @@ ...@@ -22,7 +22,13 @@
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
import { Component, Input, SimpleChanges } from '@angular/core'; 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 { import {
getUserName, getUserName,
getUserNameInitials, getUserNameInitials,
...@@ -71,7 +77,7 @@ export class UserIconComponent { ...@@ -71,7 +77,7 @@ export class UserIconComponent {
} }
get errorMessageCode(): string { get errorMessageCode(): string {
return this.userProfileStateResource.error?.issues[0]?.messageCode; return (<ApiError>this.userProfileStateResource.error)?.issues[0]?.messageCode;
} }
get initials(): string { get initials(): string {
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*/ */
import { Component, Input } from '@angular/core'; import { Component, Input } from '@angular/core';
import { import {
ApiError,
StateResource, StateResource,
createEmptyStateResource, createEmptyStateResource,
hasError, hasError,
...@@ -45,7 +46,7 @@ export class UserProfileInVorgangComponent { ...@@ -45,7 +46,7 @@ export class UserProfileInVorgangComponent {
readonly vorgangLinkRel = VorgangWithEingangLinkRel; readonly vorgangLinkRel = VorgangWithEingangLinkRel;
public isUserServiceAvailable(stateResource: StateResource<Resource>): boolean { public isUserServiceAvailable(stateResource: StateResource<Resource>): boolean {
if (hasError(stateResource) && isServiceUnavailableMessageCode(stateResource.error)) { if (hasError(stateResource) && isServiceUnavailableMessageCode(<ApiError>stateResource.error)) {
return false; return false;
} }
return true; return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment