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 { 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),
});
}
......
......@@ -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]);
......
......@@ -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);
});
......
......@@ -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;
}
......@@ -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();
......
......@@ -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 {
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment