diff --git a/src/app/shared/address-input/address-input.component.html b/src/app/shared/address-input/address-input.component.html index 50f291661f..70bdaabdf1 100644 --- a/src/app/shared/address-input/address-input.component.html +++ b/src/app/shared/address-input/address-input.component.html @@ -16,6 +16,7 @@ +
component.types.some((t) => type.includes(t))); + private findValue(response: google.maps.GeocoderResult, ...types: string[]): google.maps.GeocoderAddressComponent { + for (const type of types) { + const value = response.address_components.find((component) => component.types.some((t) => type === t)); + + if (value) { + return value; + } + } + + return null; } } diff --git a/src/app/ubs/ubs/validators/address-olready-exists-validator.ts b/src/app/ubs/ubs/validators/address-olready-exists-validator.ts index 7ecbd6128b..092808ebd0 100644 --- a/src/app/ubs/ubs/validators/address-olready-exists-validator.ts +++ b/src/app/ubs/ubs/validators/address-olready-exists-validator.ts @@ -12,10 +12,13 @@ export function addressAlreadyExistsValidator( getLangValue(address.region, address.regionEn, currentLanguage) === group.controls?.region.value && getLangValue(address.city, address.cityEn, currentLanguage) === group.controls?.city.value && getLangValue(address.street, address.streetEn, currentLanguage) === group.controls?.street.value && - address.district === group.controls?.district.value?.nameUa && address.houseNumber === group.controls?.houseNumber.value && - address.houseCorpus === group.controls?.houseCorpus.value && - address.entranceNumber === group.controls?.entranceNumber.value + compareIfExist(group.controls?.houseCorpus.value, address.houseCorpus) && + compareIfExist(group.controls?.entranceNumber.value, address.entranceNumber) && + (address.district === group.controls?.district.value?.nameUa || + address.districtEn === group.controls?.district.value?.nameEn || + address.district === group.controls?.district.value || + address.districtEn === group.controls?.district.value) ); return isAlreadyExist ? { addressAlreadyExists: true } : null; @@ -25,3 +28,11 @@ export function addressAlreadyExistsValidator( function getLangValue(valUA: any, valEN: any, currentLanguage: Language): any { return currentLanguage === Language.EN ? valEN : valUA; } + +function compareIfExist(value: any, compareTo: any): boolean { + if (!value) { + return true; + } + + return value === compareTo; +}