From 1b938b2c1023fce0bf65a21bcaaf81e8fcfbd81f Mon Sep 17 00:00:00 2001 From: Emad <121242386+esdd1995@users.noreply.github.com> Date: Tue, 24 Sep 2024 16:26:57 -0700 Subject: [PATCH] Emad/identity confirm (#1431) # Description This PR includes the following proposed change(s): SPDBT-2978](https://jag.gov.bc.ca/jira/browse/SPDBT-2978 - refactored `CommitApplicationAsync` - using spd_origin, defining spd_Identityconfirmed. --- src/Spd.Manager.Licence/BizLicAppManager.cs | 4 +++- .../ControllingMemberCrcAppManager.cs | 5 +++-- .../LicenceAppManagerBase.cs | 22 +++++++++++++------ src/Spd.Manager.Licence/PermitAppManager.cs | 2 +- .../BizLicApplication/Mappings.cs | 1 + .../Mappings.cs | 1 + .../LicApp/LicAppRepository.cs | 11 +++------- .../PersonLicApplication/Mappings.cs | 1 + .../SharedMappingFuncs.cs | 8 +++++++ .../SharedRepositoryFuncs.cs | 1 - 10 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/Spd.Manager.Licence/BizLicAppManager.cs b/src/Spd.Manager.Licence/BizLicAppManager.cs index 5b28c212d..09a20017b 100644 --- a/src/Spd.Manager.Licence/BizLicAppManager.cs +++ b/src/Spd.Manager.Licence/BizLicAppManager.cs @@ -124,7 +124,9 @@ public async Task Handle(BizLicAppSubmitCommand cmd, C //move files from transient bucket to main bucket when app status changed to Submitted. await MoveFilesAsync((Guid)cmd.BizLicAppUpsertRequest.LicenceAppId, cancellationToken); - decimal cost = await CommitApplicationAsync(cmd.BizLicAppUpsertRequest, cmd.BizLicAppUpsertRequest.LicenceAppId.Value, cancellationToken, false, cmd.BizLicAppUpsertRequest.SoleProprietorSWLAppId); + decimal cost = await CommitApplicationAsync(cmd.BizLicAppUpsertRequest, cmd.BizLicAppUpsertRequest.LicenceAppId.Value, cancellationToken, + HasSwl90DayLicence: false, + cmd.BizLicAppUpsertRequest.SoleProprietorSWLAppId); return new BizLicAppCommandResponse { LicenceAppId = response.LicenceAppId, Cost = cost }; } diff --git a/src/Spd.Manager.Licence/ControllingMemberCrcAppManager.cs b/src/Spd.Manager.Licence/ControllingMemberCrcAppManager.cs index 421a8bf01..7084d3cc8 100644 --- a/src/Spd.Manager.Licence/ControllingMemberCrcAppManager.cs +++ b/src/Spd.Manager.Licence/ControllingMemberCrcAppManager.cs @@ -160,7 +160,7 @@ await ValidateInviteIdAsync(cmd.ControllingMemberCrcAppSubmitRequest.InviteId, await UploadNewDocsAsync(request.DocumentExpiredInfos, cmd.LicAppFileInfos, response.ControllingMemberAppId, response.ContactId, null, null, null, null, null, ct); //commit app - await _licAppRepository.CommitLicenceApplicationAsync(response.ControllingMemberAppId, ApplicationStatusEnum.PaymentPending, null, ct); + await CommitApplicationAsync(new LicenceAppBase() { ApplicationTypeCode = request.ApplicationTypeCode, ApplicationOriginTypeCode = request.ApplicationOriginTypeCode}, response.ControllingMemberAppId, ct); await DeactiveInviteAsync(cmd.ControllingMemberCrcAppSubmitRequest.InviteId, ct); return _mapper.Map(response); @@ -187,10 +187,11 @@ await UpdateDocumentsAsync( public async Task Handle(ControllingMemberCrcSubmitCommand cmd, CancellationToken ct) { ValidateFilesForNewAppAuthenticated(cmd); + var request = cmd.ControllingMemberCrcUpsertRequest; var response = await this.Handle((ControllingMemberCrcUpsertCommand)cmd, ct); //move files from transient bucket to main bucket when app status changed to PaymentPending. await MoveFilesAsync(response.ControllingMemberAppId, ct); - await _licAppRepository.CommitLicenceApplicationAsync(response.ControllingMemberAppId, ApplicationStatusEnum.PaymentPending, null, ct); + await CommitApplicationAsync(new LicenceAppBase() { ApplicationTypeCode = request.ApplicationTypeCode, ApplicationOriginTypeCode = request.ApplicationOriginTypeCode }, response.ControllingMemberAppId, ct); await DeactiveInviteAsync(cmd.ControllingMemberCrcAppUpsertRequest.InviteId, ct); return new ControllingMemberCrcAppCommandResponse { ControllingMemberAppId = response.ControllingMemberAppId }; } diff --git a/src/Spd.Manager.Licence/LicenceAppManagerBase.cs b/src/Spd.Manager.Licence/LicenceAppManagerBase.cs index dc3a0f857..ca8c0b7e3 100644 --- a/src/Spd.Manager.Licence/LicenceAppManagerBase.cs +++ b/src/Spd.Manager.Licence/LicenceAppManagerBase.cs @@ -51,17 +51,25 @@ protected async Task CommitApplicationAsync(LicenceAppBase licAppBase, HasValidSwl90DayLicence = HasSwl90DayLicence }, ct); LicenceFeeResp? licenceFee = price?.LicenceFees.FirstOrDefault(); + + //applications with portal origin type are considered authenticated, otherwise not. + bool IsAuthenticated = licAppBase.ApplicationOriginTypeCode == Shared.ApplicationOriginTypeCode.Portal ? true : false; + bool isNewOrRenewal = licAppBase.ApplicationTypeCode == Shared.ApplicationTypeCode.New || licAppBase.ApplicationTypeCode == Shared.ApplicationTypeCode.Renewal; + ApplicationStatusEnum status; + if (licenceFee == null || licenceFee.Amount == 0) - { - if (companionAppId != null) await _licAppRepository.CommitLicenceApplicationAsync((Guid)companionAppId, ApplicationStatusEnum.Submitted, null, ct); - await _licAppRepository.CommitLicenceApplicationAsync(licenceAppId, ApplicationStatusEnum.Submitted, null, ct); - } + status = isNewOrRenewal && !IsAuthenticated ? ApplicationStatusEnum.ApplicantVerification : ApplicationStatusEnum.Submitted; else + status = ApplicationStatusEnum.PaymentPending; + + // Commit the companion application if it exists + //companionAppId is the swl for sole proprietor which the business would pay for it, therefore the licence fee should be null here. + if (companionAppId != null) { - //companionAppId is the swl for sole proprietor which the business would pay for it, therefore the licence fee should be null here. - if (companionAppId != null) await _licAppRepository.CommitLicenceApplicationAsync((Guid)companionAppId, ApplicationStatusEnum.PaymentPending, null, ct); - await _licAppRepository.CommitLicenceApplicationAsync(licenceAppId, ApplicationStatusEnum.PaymentPending, licenceFee.Amount, ct); + await _licAppRepository.CommitLicenceApplicationAsync((Guid)companionAppId, ApplicationStatusEnum.PaymentPending, null, ct); } + // Commit the main licence application + await _licAppRepository.CommitLicenceApplicationAsync(licenceAppId, status, licenceFee?.Amount, ct); return licenceFee?.Amount ?? 0; } diff --git a/src/Spd.Manager.Licence/PermitAppManager.cs b/src/Spd.Manager.Licence/PermitAppManager.cs index 173713da0..be14a926c 100644 --- a/src/Spd.Manager.Licence/PermitAppManager.cs +++ b/src/Spd.Manager.Licence/PermitAppManager.cs @@ -191,7 +191,7 @@ public async Task Handle(PermitAppRenewCommand cmd, Ca await ValidateFilesForRenewUpdateAppAsync(cmd.LicenceAnonymousRequest, cmd.LicAppFileInfos.ToList(), cancellationToken); - + CreateLicenceApplicationCmd createApp = _mapper.Map(request); createApp.UploadedDocumentEnums = GetUploadedDocumentEnums(cmd.LicAppFileInfos, existingFiles); LicenceApplicationCmdResp response = await _personLicAppRepository.CreateLicenceApplicationAsync(createApp, cancellationToken); diff --git a/src/Spd.Resource.Repository/BizLicApplication/Mappings.cs b/src/Spd.Resource.Repository/BizLicApplication/Mappings.cs index acae7c83c..b2a7cc035 100644 --- a/src/Spd.Resource.Repository/BizLicApplication/Mappings.cs +++ b/src/Spd.Resource.Repository/BizLicApplication/Mappings.cs @@ -35,6 +35,7 @@ public Mappings() .ForMember(d => d.spd_declaration, opt => opt.MapFrom(s => s.AgreeToCompleteAndAccurate)) .ForMember(d => d.spd_consent, opt => opt.MapFrom(s => s.AgreeToCompleteAndAccurate)) .ForMember(d => d.spd_declarationdate, opt => opt.MapFrom(s => GetDeclarationDate(s))) + .ForMember(d => d.spd_identityconfirmed, opt => opt.MapFrom(s => SharedMappingFuncs.GetIdentityConfirmed(s.ApplicationOriginTypeCode, s.ApplicationTypeCode))) .ReverseMap() .ForMember(d => d.WorkerLicenceTypeCode, opt => opt.MapFrom(s => SharedMappingFuncs.GetServiceType(s._spd_servicetypeid_value))) .ForMember(d => d.ApplicationOriginTypeCode, opt => opt.MapFrom(s => SharedMappingFuncs.GetEnum(s.spd_origin))) diff --git a/src/Spd.Resource.Repository/ControllingMemberCrcApplication/Mappings.cs b/src/Spd.Resource.Repository/ControllingMemberCrcApplication/Mappings.cs index 53a643aff..d83a3d4ab 100644 --- a/src/Spd.Resource.Repository/ControllingMemberCrcApplication/Mappings.cs +++ b/src/Spd.Resource.Repository/ControllingMemberCrcApplication/Mappings.cs @@ -90,6 +90,7 @@ public Mappings() .ForMember(d => d.spd_uploadeddocuments, opt => opt.MapFrom(s => SharedMappingFuncs.GetUploadedDocumentOptionSets(s.UploadedDocumentEnums))) .ForMember(d => d.spd_criminalchargesconvictionsdetails, opt => opt.MapFrom(s => s.CriminalHistoryDetail)) .ForMember(d => d.spd_portalmodifiedon, opt => opt.MapFrom(s => DateTimeOffset.UtcNow)) + .ForMember(d => d.spd_identityconfirmed, opt => opt.MapFrom(s => SharedMappingFuncs.GetIdentityConfirmed(s.ApplicationOriginTypeCode, s.ApplicationTypeCode))) .ReverseMap() .ForMember(d => d.EmailAddress, opt => opt.MapFrom(s => s.spd_emailaddress1)) .ForMember(d => d.ApplicationOriginTypeCode, opt => opt.MapFrom(s => SharedMappingFuncs.GetEnum(s.spd_origin))) diff --git a/src/Spd.Resource.Repository/LicApp/LicAppRepository.cs b/src/Spd.Resource.Repository/LicApp/LicAppRepository.cs index 7203fb125..ba009c983 100644 --- a/src/Spd.Resource.Repository/LicApp/LicAppRepository.cs +++ b/src/Spd.Resource.Repository/LicApp/LicAppRepository.cs @@ -24,16 +24,11 @@ public async Task CommitLicenceApplicationAsync(Guid if (app == null) throw new ApiException(HttpStatusCode.BadRequest, "Invalid ApplicationId"); + app.statuscode = (int)Enum.Parse(status.ToString()); + if (status == ApplicationStatusEnum.Submitted) - { - app.statuscode = (int)ApplicationStatusOptionSet.Submitted; app.statecode = DynamicsConstants.StateCode_Inactive; - } - else - { - app.statuscode = (int)Enum.Parse(status.ToString()); - } - + app.spd_submittedon = DateTimeOffset.Now; app.spd_portalmodifiedon = DateTimeOffset.Now; if (price is > 0) diff --git a/src/Spd.Resource.Repository/PersonLicApplication/Mappings.cs b/src/Spd.Resource.Repository/PersonLicApplication/Mappings.cs index 7535200aa..c01efa00e 100644 --- a/src/Spd.Resource.Repository/PersonLicApplication/Mappings.cs +++ b/src/Spd.Resource.Repository/PersonLicApplication/Mappings.cs @@ -131,6 +131,7 @@ public Mappings() .ForMember(d => d.spd_uploadeddocuments, opt => opt.MapFrom(s => SharedMappingFuncs.GetUploadedDocumentOptionSets(s.UploadedDocumentEnums))) .ForMember(d => d.spd_criminalchargesconvictionsdetails, opt => opt.MapFrom(s => s.CriminalChargeDescription)) .ForMember(d => d.spd_portalmodifiedon, opt => opt.MapFrom(s => DateTimeOffset.UtcNow)) + .ForMember(d => d.spd_identityconfirmed, opt => opt.MapFrom(s => SharedMappingFuncs.GetIdentityConfirmed(s.ApplicationOriginTypeCode, s.ApplicationTypeCode))) .ReverseMap() .ForMember(d => d.ContactEmailAddress, opt => opt.Ignore()) .ForMember(d => d.DateOfBirth, opt => opt.Ignore()) diff --git a/src/Spd.Resource.Repository/SharedMappingFuncs.cs b/src/Spd.Resource.Repository/SharedMappingFuncs.cs index bb2acbc28..53352423e 100644 --- a/src/Spd.Resource.Repository/SharedMappingFuncs.cs +++ b/src/Spd.Resource.Repository/SharedMappingFuncs.cs @@ -205,4 +205,12 @@ internal static IEnumerable GetUploadedDocumentEnums(strin return Enum.Parse( DynamicsContextLookupHelpers.RoleGuidDictionary.FirstOrDefault(x => x.Value == role.spd_roleid).Key); } + internal static bool GetIdentityConfirmed(ApplicationOriginTypeCode? origin, ApplicationTypeEnum type) + { + bool isNotPortal = origin != ApplicationOriginTypeCode.Portal; + bool isNewOrRenewal = type == ApplicationTypeEnum.New || + type == ApplicationTypeEnum.Renewal; + + return !(isNotPortal && isNewOrRenewal); + } } \ No newline at end of file diff --git a/src/Spd.Resource.Repository/SharedRepositoryFuncs.cs b/src/Spd.Resource.Repository/SharedRepositoryFuncs.cs index 1600c46dd..d408cff2d 100644 --- a/src/Spd.Resource.Repository/SharedRepositoryFuncs.cs +++ b/src/Spd.Resource.Repository/SharedRepositoryFuncs.cs @@ -62,5 +62,4 @@ public static void LinkTeam(DynamicsContext _context, string teamGuidStr, spd_ap ).ToList(); return matchingAliases; } - } \ No newline at end of file