Merge pull request #169 in TEA/mina-sidor-fa-web from bugfix/TV-718 to develop
Squashed commit of the following: commit 798af49b3e42f9d593b23d9fad1dc90aaf93e6af Author: fueno <nicolas.fuentes-maturana@arbetsformedlingen.se> Date: Mon Oct 4 17:23:10 2021 +0200 TV-718 update enum values commit 15fc401f8d995e7d991b7930c5295950b5954f13 Author: fueno <nicolas.fuentes-maturana@arbetsformedlingen.se> Date: Mon Oct 4 17:22:45 2021 +0200 TV-718 lower case on methods, cleaning, commit 900b72e5b0eda2dae36e7c315aa851c0117cad4e Author: fueno <nicolas.fuentes-maturana@arbetsformedlingen.se> Date: Mon Oct 4 17:05:30 2021 +0200 TV-718 updated heading commit 23f6077ebce03d61bc7bd65125d072916a2bfb51 Merge: b9c76e14f68eadbdAuthor: fueno <nicolas.fuentes-maturana@arbetsformedlingen.se> Date: Mon Oct 4 16:28:12 2021 +0200 Merge branch 'develop' into bugfix/TV-718 commit b9c76e1489729c4703d9db12e0724fd6db066386 Author: fueno <nicolas.fuentes-maturana@arbetsformedlingen.se> Date: Mon Oct 4 13:21:34 2021 +0200 TV-718 dont send contactInformatin in payload commit d636eaea7148b2aef1d67cf65612c0f1fd52de15 Author: fueno <nicolas.fuentes-maturana@arbetsformedlingen.se> Date: Mon Oct 4 11:44:38 2021 +0200 TV 718: update some headings and corr misspelling commit 68d355858b4fefc159448e34238267e0f3253824 Author: fueno <nicolas.fuentes-maturana@arbetsformedlingen.se> Date: Mon Oct 4 09:20:39 2021 +0200 TV-718 deleted console log commit 742dbba8859053786924c0a3a6da3f0f22654397 Merge: d961c55993556d48Author: fueno <nicolas.fuentes-maturana@arbetsformedlingen.se> Date: Mon Oct 4 08:45:57 2021 +0200 Merge branch 'develop' into bugfix/TV-718 commit d961c559837edb81976f3e5756fa63b450b57d24 Author: fueno <nicolas.fuentes-maturana@arbetsformedlingen.se> Date: Mon Oct 4 08:45:25 2021 +0200 TV-718 validation works, refactoring commit 5f89417a63757b7e51bcda382da86ed73a4dd042 Author: fueno <nicolas.fuentes-maturana@arbetsformedlingen.se> Date: Fri Oct 1 11:08:25 2021 +0200 TV-718 validator fixes
This commit is contained in:
@@ -3,113 +3,169 @@ import { Alternative } from '@msfa-enums/alternative.enum';
|
||||
import { DayOrPartOfDay } from '@msfa-enums/day-or-part-of-day.enum';
|
||||
import { FranvaroOrsaksKodEnum } from '@msfa-enums/franvaro-orsak-kod.enum';
|
||||
import { KandaOrsakerEnum } from '@msfa-enums/kanda-orsaker-kod.enum';
|
||||
import { ValidationError } from '@msfa-models/validation-error.model';
|
||||
|
||||
export class DescriptionIsRequiredCheck {
|
||||
static CheckIfRequired(
|
||||
controlToValidateName: string,
|
||||
nestedFormGroupName: string,
|
||||
nestedFormGroupControlName: string,
|
||||
valueForWhichTheControlShouldBeRequired: KandaOrsakerEnum
|
||||
): ValidatorFn {
|
||||
return (fg: AbstractControl): { [key: string]: boolean } => {
|
||||
const valueOfControlToValidate = fg?.get(controlToValidateName)?.value as string;
|
||||
const valueOfNestedFormControl = fg?.get(nestedFormGroupName)?.get(nestedFormGroupControlName)?.value as string;
|
||||
const isRequired = +valueOfNestedFormControl === valueForWhichTheControlShouldBeRequired && valueOfControlToValidate === '';
|
||||
|
||||
return isRequired ? { descriptionIsRequired: true } : null;
|
||||
};
|
||||
}
|
||||
export interface Controls {
|
||||
[key: string]: AbstractControl
|
||||
}
|
||||
|
||||
export class OrsakerIsRequiredCheck {
|
||||
static CheckIfRequired(
|
||||
nestedFormGroupName: string,
|
||||
controlToValidateName: string,
|
||||
): ValidatorFn {
|
||||
return (fg: AbstractControl): { [key: string]: boolean } => {
|
||||
const valueOfNestedFormControl = fg?.get(nestedFormGroupName)?.get(controlToValidateName)?.value as string;
|
||||
const isRequired = valueOfNestedFormControl === null && fg?.get(nestedFormGroupName)?.get('andraKandaOrsaker')?.value === null;
|
||||
export function requiredDescriptionValidator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
const ctrls = control?.parent?.controls as Controls;
|
||||
|
||||
return isRequired ? { orsakerIsRequired: true } : null;
|
||||
};
|
||||
}
|
||||
}
|
||||
if (ctrls) {
|
||||
const valueOfNestedFormControl = ctrls['orsakerFormGroup'].get('andraKandaOrsaker').value as string;
|
||||
const valueOfFormControl = control.value as string;
|
||||
const isRequired = !valueOfFormControl && +valueOfNestedFormControl === KandaOrsakerEnum.AnnanOrsak;
|
||||
|
||||
export class DayOrPartOfDayIsRequiredCheck {
|
||||
static CheckIfRequired(
|
||||
controlToValidateName: string,
|
||||
): ValidatorFn {
|
||||
return (fg: AbstractControl): { [key: string]: boolean } => {
|
||||
const valueOfControlToValidate = fg?.get(controlToValidateName)?.value as string;
|
||||
const isRequired = valueOfControlToValidate === null && fg?.get('alternative').value === Alternative.FRANVARO;
|
||||
if (isRequired) {
|
||||
return { type: 'required', message: 'Beskrivning är obligatoriskt' }
|
||||
}
|
||||
|
||||
return isRequired ? { dayOrPartOfDayIsRequired: true } : null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class AnnanKandOrsakeIsRequiredCheck {
|
||||
static CheckIfRequired(
|
||||
nestedFormGroupName: string,
|
||||
controlToValidateName: string,
|
||||
): ValidatorFn {
|
||||
return (fg: AbstractControl): { [key: string]: boolean } => {
|
||||
const valueOfNestedFormControl = fg?.get(nestedFormGroupName)?.get(controlToValidateName)?.value as string;
|
||||
const isRequired = +fg?.get(nestedFormGroupName).get('orsaker').value === FranvaroOrsaksKodEnum.AnnanKandOrsak &&
|
||||
valueOfNestedFormControl === null;
|
||||
|
||||
return isRequired ? { annanKandorsakIsRequired: true } : null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class StartTimeIsRequiredCheck {
|
||||
static CheckIfRequired(
|
||||
nestedFormGroupName: string,
|
||||
startTimeControlToValidateName: string,
|
||||
): ValidatorFn {
|
||||
return (fg: AbstractControl): { [key: string]: boolean } => {
|
||||
const valueOfStartTimeFormControl = fg?.get(nestedFormGroupName)?.get(startTimeControlToValidateName)?.value as string;
|
||||
const isRequired = fg?.get('alternative')?.value as string === Alternative.FRANVARO &&
|
||||
fg?.get('dayOrPartOfDay').value === DayOrPartOfDay.DEL_AV_DAG && !valueOfStartTimeFormControl;
|
||||
|
||||
return isRequired ? { startTimeIsRequired: true } : null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class EndTimeIsRequiredCheck {
|
||||
static CheckIfRequired(
|
||||
nestedFormGroupName: string,
|
||||
endTimeControlToValidateName: string
|
||||
): ValidatorFn {
|
||||
return (fg: AbstractControl): { [key: string]: boolean } => {
|
||||
const valueOfEndTimeFormControl = fg?.get(nestedFormGroupName)?.get(endTimeControlToValidateName)?.value as string;
|
||||
const isRequired = fg?.get('alternative').value as string === Alternative.FRANVARO &&
|
||||
fg?.get('dayOrPartOfDay').value === DayOrPartOfDay.DEL_AV_DAG && !valueOfEndTimeFormControl;
|
||||
export function requiredOrsakerValidator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
const ctrls = control?.parent?.controls as Controls;
|
||||
|
||||
return isRequired ? { endTimeIsRequired: true } : null;
|
||||
if (ctrls) {
|
||||
const valueOfNestedFormControl = ctrls['orsaker'].value as string;
|
||||
const isRequired = !valueOfNestedFormControl && !ctrls['andraKandaOrsaker'].value;
|
||||
|
||||
if (isRequired) {
|
||||
return { type: 'required', message: `Orsak är obligatoriskt` };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class MotiveringIsRequiredCheck {
|
||||
static CheckIfRequired(controlToValidateName: string): ValidatorFn {
|
||||
return (fg: AbstractControl): { [key: string]: boolean } => {
|
||||
const valueOfControlToValidate = fg?.get('fragorFormGroup').get(controlToValidateName)?.value as string;
|
||||
const isRequired = fg?.get('alternative').value as string === Alternative.AVVIKELSE && valueOfControlToValidate === '';
|
||||
export function requiredAnnanKandOrsakValidator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
const ctrls = control?.parent?.controls as Controls;
|
||||
|
||||
return isRequired ? { motiveringIsRequired: true } : null;
|
||||
};
|
||||
if (ctrls) {
|
||||
const isAnnanKandOrsak = +ctrls['orsaker'].value === FranvaroOrsaksKodEnum.AnnanKandOrsak;
|
||||
const valueOfNestedFormControl = ctrls['andraKandaOrsaker'].value as string;
|
||||
const isRequired = isAnnanKandOrsak && !valueOfNestedFormControl;
|
||||
|
||||
if (isRequired) {
|
||||
return { type: 'required', message: `Annan orsak är obligatoriskt` };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
export class DateIsRequiredCheck {
|
||||
static CheckIfRequired(controlToValidateName: string): ValidatorFn {
|
||||
|
||||
export class RequiredDateValidator {
|
||||
static CheckIfRequired(): ValidatorFn {
|
||||
return (fg: AbstractControl): { [key: string]: string } => {
|
||||
const valueOfControlToValidate = fg?.get(controlToValidateName).value as string;
|
||||
const isRequired = valueOfControlToValidate === '';
|
||||
const valueOfFormControl = fg?.get('date')?.value as string;
|
||||
const isRequired = !valueOfFormControl;
|
||||
|
||||
return isRequired ? { dateIsRequired: 'Datum är obligatoriskt' } : null;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function requiredDayOrPartOfDayValidator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
const ctrls = control?.parent?.controls as Controls;
|
||||
|
||||
if (ctrls) {
|
||||
const isFranvaro = ctrls['alternative'].value === Alternative.FRANVARO;
|
||||
const valueOfFormControl = control.value as string;
|
||||
const isRequired = isFranvaro && !valueOfFormControl;
|
||||
|
||||
if (isRequired) {
|
||||
return { type: 'required', message: `Hel- eller del av dag är obligatoriskt` };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function requiredStartTimeValidator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
const ctrls = control?.parent?.parent?.controls as Controls;
|
||||
|
||||
if (ctrls) {
|
||||
const isFranvaro = ctrls['alternative']?.value as string === Alternative.FRANVARO;
|
||||
const isPartOfDay = ctrls['dayOrPartOfDay']?.value === DayOrPartOfDay.DEL_AV_DAG;
|
||||
const valueOfFormControl = control?.value as string;
|
||||
const isRequired = isFranvaro && isPartOfDay && (valueOfFormControl === '' || valueOfFormControl === null);
|
||||
|
||||
if (isRequired) {
|
||||
return { type: 'required', message: `Starttid är obligatoriskt` };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function requiredEndTimeValidator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
const ctrls = control?.parent?.parent?.controls as Controls;
|
||||
|
||||
if (ctrls) {
|
||||
const isFranvaro = ctrls['alternative']?.value as string === Alternative.FRANVARO;
|
||||
const isPartOfDay = ctrls['dayOrPartOfDay']?.value === DayOrPartOfDay.DEL_AV_DAG;
|
||||
const valueOfFormControl = control?.value as string;
|
||||
const isRequired = isFranvaro && isPartOfDay && (valueOfFormControl === '' || valueOfFormControl === null);
|
||||
|
||||
if (isRequired) {
|
||||
return { type: 'required', message: `Sluttid är obligatoriskt` };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function requiredFraga1Validator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
const ctrls = control?.parent?.parent?.controls as Controls;
|
||||
|
||||
if (ctrls) {
|
||||
const isAvvikelse = ctrls['alternative']?.value === 'avvikelse';
|
||||
const valueOfFormControl = control.value as string;
|
||||
const isRequired = isAvvikelse && !valueOfFormControl;
|
||||
|
||||
if (isRequired) {
|
||||
return { type: 'required', message: `Beskrivning är obligatoriskt` };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function requiredfraga2Validator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
const ctrls = control?.parent?.parent?.controls as Controls;
|
||||
|
||||
if (ctrls) {
|
||||
const isAvvikelse = ctrls['alternative']?.value === 'avvikelse';
|
||||
const valueOfFormControl = control.value as string;
|
||||
const orsaksKodToValidate = ctrls['orsakerFormGroup']?.get('orsaker')?.value as string;
|
||||
const isRequired = isAvvikelse && !valueOfFormControl &&
|
||||
(orsaksKodToValidate !== '19' &&
|
||||
orsaksKodToValidate !== '20' &&
|
||||
orsaksKodToValidate !== '28'
|
||||
)
|
||||
|
||||
if (isRequired) {
|
||||
return { type: 'required', message: `Beskrivning är obligatoriskt` };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user