From d2f2b257cc7c1787c19322b49aeac281c5ac8b1b Mon Sep 17 00:00:00 2001 From: Carol Carpenter Date: Mon, 6 May 2024 15:05:27 -0700 Subject: [PATCH] more shared code --- .../src/app/core/services/util.service.ts | 31 ++++++++++++++++++- .../manual-submission-common.component.ts | 13 +++----- ...ning-request-add-common-modal.component.ts | 14 +++------ 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/Spd.Presentation.Screening/ClientApp/src/app/core/services/util.service.ts b/src/Spd.Presentation.Screening/ClientApp/src/app/core/services/util.service.ts index 42cce913e..d43051544 100644 --- a/src/Spd.Presentation.Screening/ClientApp/src/app/core/services/util.service.ts +++ b/src/Spd.Presentation.Screening/ClientApp/src/app/core/services/util.service.ts @@ -4,7 +4,12 @@ import { Inject, Injectable } from '@angular/core'; import { HotToastService } from '@ngneat/hot-toast'; import jwt_decode from 'jwt-decode'; import * as moment from 'moment'; -import { ApplicationPortalStatusCode, PaginationResponse, ScreeningTypeCode } from 'src/app/api/models'; +import { + ApplicationPortalStatusCode, + BooleanTypeCode, + PaginationResponse, + ScreeningTypeCode, +} from 'src/app/api/models'; import * as CodeDescTypes from 'src/app/core/code-types/code-desc-types.models'; import { ApplicationPortalStatusTypes, ScreeningTypes, SelectOptions } from '../code-types/model-desc.models'; import { SPD_CONSTANTS } from '../constants/constants'; @@ -273,6 +278,30 @@ export class UtilService { } } + /** + * Convert BooleanTypeCode to boolean + * @param value + * @returns + */ + booleanTypeToBoolean(value: BooleanTypeCode | undefined | null): boolean | null { + if (!value) return null; + + if (value == BooleanTypeCode.Yes) return true; + return false; + } + + /** + * Convert boolean to BooleanTypeCode + * @param value + * @returns + */ + public booleanToBooleanType(value: boolean | null | undefined): BooleanTypeCode | null { + const isBooleanType = typeof value === 'boolean'; + if (!isBooleanType) return null; + + return value ? BooleanTypeCode.Yes : BooleanTypeCode.No; + } + //------------------------------------ // Sort diff --git a/src/Spd.Presentation.Screening/ClientApp/src/app/shared/components/manual-submission-common.component.ts b/src/Spd.Presentation.Screening/ClientApp/src/app/shared/components/manual-submission-common.component.ts index 17c0ff900..ded5c12ba 100644 --- a/src/Spd.Presentation.Screening/ClientApp/src/app/shared/components/manual-submission-common.component.ts +++ b/src/Spd.Presentation.Screening/ClientApp/src/app/shared/components/manual-submission-common.component.ts @@ -587,18 +587,13 @@ export class ManualSubmissionCommonComponent implements OnInit { this.isNotVolunteerOrg = orgProfile?.isNotVolunteerOrg ?? false; if (this.isNotVolunteerOrg) { - const licenseesNeedVulnerableSectorScreening = - orgProfile.licenseesNeedVulnerableSectorScreening === BooleanTypeCode.Yes; - const contractorsNeedVulnerableSectorScreening = - orgProfile.contractorsNeedVulnerableSectorScreening === BooleanTypeCode.Yes; - this.showScreeningType = this.utilService.getShowScreeningType( - licenseesNeedVulnerableSectorScreening, - contractorsNeedVulnerableSectorScreening + this.utilService.booleanTypeToBoolean(orgProfile.licenseesNeedVulnerableSectorScreening) ?? false, + this.utilService.booleanTypeToBoolean(orgProfile.contractorsNeedVulnerableSectorScreening) ?? false ); this.screeningTypes = this.utilService.getScreeningTypes( - licenseesNeedVulnerableSectorScreening, - contractorsNeedVulnerableSectorScreening + this.utilService.booleanTypeToBoolean(orgProfile.licenseesNeedVulnerableSectorScreening) ?? false, + this.utilService.booleanTypeToBoolean(orgProfile.contractorsNeedVulnerableSectorScreening) ?? false ); } else { this.showScreeningType = false; diff --git a/src/Spd.Presentation.Screening/ClientApp/src/app/shared/components/screening-request-add-common-modal.component.ts b/src/Spd.Presentation.Screening/ClientApp/src/app/shared/components/screening-request-add-common-modal.component.ts index 9319905f8..763ef6768 100644 --- a/src/Spd.Presentation.Screening/ClientApp/src/app/shared/components/screening-request-add-common-modal.component.ts +++ b/src/Spd.Presentation.Screening/ClientApp/src/app/shared/components/screening-request-add-common-modal.component.ts @@ -7,7 +7,6 @@ import { ApplicationInvitePrepopulateDataResponse, ApplicationInvitesCreateRequest, ApplicationInvitesCreateResponse, - BooleanTypeCode, MinistryResponse, ScreeningTypeCode, ServiceTypeCode, @@ -573,18 +572,13 @@ export class ScreeningRequestAddCommonModalComponent implements OnInit { this.isNotVolunteerOrg = orgProfile?.isNotVolunteerOrg ?? false; if (this.isNotVolunteerOrg) { - const licenseesNeedVulnerableSectorScreening = - orgProfile.licenseesNeedVulnerableSectorScreening === BooleanTypeCode.Yes; - const contractorsNeedVulnerableSectorScreening = - orgProfile.contractorsNeedVulnerableSectorScreening === BooleanTypeCode.Yes; - this.showScreeningType = this.utilService.getShowScreeningType( - licenseesNeedVulnerableSectorScreening, - contractorsNeedVulnerableSectorScreening + this.utilService.booleanTypeToBoolean(orgProfile.licenseesNeedVulnerableSectorScreening) ?? false, + this.utilService.booleanTypeToBoolean(orgProfile.contractorsNeedVulnerableSectorScreening) ?? false ); this.screeningTypes = this.utilService.getScreeningTypes( - licenseesNeedVulnerableSectorScreening, - contractorsNeedVulnerableSectorScreening + this.utilService.booleanTypeToBoolean(orgProfile.licenseesNeedVulnerableSectorScreening) ?? false, + this.utilService.booleanTypeToBoolean(orgProfile.contractorsNeedVulnerableSectorScreening) ?? false ); } else { this.showScreeningType = false;