Skip to content

Commit

Permalink
[SPDBT-3352] Licensing - Create Controlling Member CRC shell Applicat…
Browse files Browse the repository at this point in the history
…ion when No Email is provided (#1962)

# Description

This PR includes the following proposed change(s):

- [SPDBT-3352] Licensing - Create Controlling Member CRC shell
Application when No Email is provided - Backend
  • Loading branch information
peggy-quartech authored Dec 4, 2024
1 parent 258e83d commit 5316258
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/Spd.Manager.Licence/BizMemberContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ public record ControllingMemberAppInviteVerifyResponse()
public enum ControllingMemberAppInviteTypeCode
{
New,
Update
Update,
CreateShellApp
}
48 changes: 37 additions & 11 deletions src/Spd.Manager.Licence/BizMemberManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Spd.Resource.Repository.Biz;
using Spd.Resource.Repository.BizContact;
using Spd.Resource.Repository.BizLicApplication;
using Spd.Resource.Repository.ControllingMemberCrcApplication;
using Spd.Resource.Repository.ControllingMemberInvite;
using Spd.Resource.Repository.Document;
using Spd.Resource.Repository.LicApp;
Expand Down Expand Up @@ -37,6 +38,7 @@ internal class BizMemberManager :
private readonly IBizRepository _bizRepository;
private readonly IPersonLicApplicationRepository _personLicApplicationRepository;
private readonly IControllingMemberInviteRepository _cmInviteRepository;
private readonly IControllingMemberCrcRepository _cmCrcRepository;

public BizMemberManager(
ILicenceRepository licenceRepository,
Expand All @@ -47,7 +49,8 @@ public BizMemberManager(
IMainFileStorageService mainFileStorageService,
ITransientFileStorageService transientFileStorageService,
IBizContactRepository bizContactRepository,
IControllingMemberInviteRepository cmInviteRepository)
IControllingMemberInviteRepository cmInviteRepository,
IControllingMemberCrcRepository cmCrcRepository)
: base(mapper,
documentUrlRepository,
feeRepository,
Expand All @@ -58,6 +61,7 @@ public BizMemberManager(
{
_bizContactRepository = bizContactRepository;
_cmInviteRepository = cmInviteRepository;
_cmCrcRepository = cmCrcRepository;
}

public async Task<ControllingMemberAppInviteVerifyResponse> Handle(VerifyBizControllingMemberInviteCommand cmd, CancellationToken cancellationToken)
Expand Down Expand Up @@ -108,18 +112,40 @@ public async Task<ControllingMemberInvitesCreateResponse> Handle(BizControllingM
throw new ApiException(HttpStatusCode.BadRequest, "Cannot find the non-swl controlling member.");
if (contactResp.BizContactRoleCode != BizContactRoleEnum.ControllingMember)
throw new ApiException(HttpStatusCode.BadRequest, "Cannot send out invitation for non-swl controlling member.");
if (string.IsNullOrWhiteSpace(contactResp.EmailAddress))
if (cmd.InviteTypeCode != ControllingMemberAppInviteTypeCode.CreateShellApp && string.IsNullOrWhiteSpace(contactResp.EmailAddress))
throw new ApiException(HttpStatusCode.BadRequest, "Cannot send out invitation when there is no email address provided.");
//if (contactResp.LatestControllingMemberCrcAppPortalStatusEnum != null &&
// contactResp.LatestControllingMemberCrcAppPortalStatusEnum != ApplicationPortalStatusEnum.CompletedCleared)
// throw new ApiException(HttpStatusCode.BadRequest, "This business contact already has a CRC application");

var createCmd = _mapper.Map<ControllingMemberInviteCreateCmd>(contactResp);
createCmd.CreatedByUserId = cmd.UserId;
createCmd.HostUrl = cmd.HostUrl;
createCmd.InviteTypeCode = Enum.Parse<ControllingMemberAppInviteTypeEnum>(cmd.InviteTypeCode.ToString());
await _cmInviteRepository.ManageAsync(createCmd, cancellationToken);

if (cmd.InviteTypeCode == ControllingMemberAppInviteTypeCode.CreateShellApp)
{
var createShellApp = _mapper.Map<SaveControllingMemberCrcAppCmd>(contactResp);
//get biz app id
IEnumerable<LicenceAppListResp> list = await _licAppRepository.QueryAsync(
new LicenceAppQuery(
null,
contactResp.BizId,
new List<ServiceTypeEnum> { ServiceTypeEnum.SecurityBusinessLicence },
new List<ApplicationPortalStatusEnum>
{
ApplicationPortalStatusEnum.Draft,
ApplicationPortalStatusEnum.Incomplete,
ApplicationPortalStatusEnum.VerifyIdentity,
ApplicationPortalStatusEnum.AwaitingPayment
}),
cancellationToken);
LicenceAppListResp? app = list.Where(a => a.ApplicationTypeCode != ApplicationTypeEnum.Replacement)
.OrderByDescending(a => a.CreatedOn)
.FirstOrDefault();
createShellApp.ParentBizLicApplicationId = app?.LicenceAppId;
await _cmCrcRepository.CreateControllingMemberCrcApplicationAsync(createShellApp, cancellationToken);
}
else
{
var createCmd = _mapper.Map<ControllingMemberInviteCreateCmd>(contactResp);
createCmd.CreatedByUserId = cmd.UserId;
createCmd.HostUrl = cmd.HostUrl;
createCmd.InviteTypeCode = Enum.Parse<ControllingMemberAppInviteTypeEnum>(cmd.InviteTypeCode.ToString());
await _cmInviteRepository.ManageAsync(createCmd, cancellationToken);
}
return new ControllingMemberInvitesCreateResponse(cmd.BizContactId) { CreateSuccess = true };
}

Expand Down
7 changes: 7 additions & 0 deletions src/Spd.Manager.Licence/Mappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,13 @@ public Mappings()
.IncludeBase<BizContactResp, ControllingMemberInvite>()
.ForMember(d => d.HostUrl, opt => opt.Ignore());

//this mapping is used for create shell app for no-email bizContact
CreateMap<BizContactResp, SaveControllingMemberCrcAppCmd>()
.ForMember(d => d.ServiceTypeCode, opt => opt.MapFrom(s => ServiceTypeEnum.SECURITY_BUSINESS_LICENCE_CONTROLLING_MEMBER_CRC))
.ForMember(d => d.ApplicationTypeCode, opt => opt.MapFrom(s => ApplicationTypeEnum.New))
.ForMember(d => d.ApplicationOriginTypeCode, opt => opt.MapFrom(_ => (ApplicationOriginTypeEnum?)null))
.ForMember(d => d.AgreeToCompleteAndAccurate, opt => opt.MapFrom(s => false));

CreateMap<BizContactResp, ControllingMemberAppInviteVerifyResponse>()
.ForMember(d => d.InviteId, opt => opt.Ignore())
.ForMember(d => d.BizContactId, opt => opt.Ignore())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public record ControllingMemberCrcApplication
public string? MiddleName2 { get; set; }
public string? Surname { get; set; }
public bool? AgreeToCompleteAndAccurate { get; set; }
public DateOnly DateOfBirth { get; set; }
public DateOnly DateOfBirth { get; set; } = new DateOnly(1800, 1, 1);
public GenderEnum? GenderCode { get; set; }
public string? PhoneNumber { get; set; }
public string? EmailAddress { get; set; }
public bool? HasPreviousName { get; set; }
public IEnumerable<AliasResp> Aliases { get; set; }
public IEnumerable<AliasResp> Aliases { get; set; } = Array.Empty<AliasResp>();
public bool? HasBcDriversLicence { get; set; }
public string? BcDriversLicenceNumber { get; set; }
public bool? IsPoliceOrPeaceOfficer { get; set; }
Expand All @@ -39,7 +39,7 @@ public record ControllingMemberCrcApplication
public string? BankruptcyHistoryDetail { get; set; }
public bool? IsTreatedForMHC { get; set; }
public ResidentialAddr? ResidentialAddressData { get; set; }
public IEnumerable<UploadedDocumentEnum>? UploadedDocumentEnums { get; set; }
public IEnumerable<UploadedDocumentEnum>? UploadedDocumentEnums { get; set; } = Array.Empty<UploadedDocumentEnum>();
public Guid BizContactId { get; set; }
}
public record CreateControllingMemberCrcAppCmd() : ControllingMemberCrcApplication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Mappings()
.ForMember(d => d.spd_lastname, opt => opt.MapFrom(s => s.Surname))
.ForMember(d => d.spd_middlename1, opt => opt.MapFrom(s => s.MiddleName1))
.ForMember(d => d.spd_middlename2, opt => opt.MapFrom(s => s.MiddleName2))
.ForMember(d => d.spd_origin, opt => opt.MapFrom(s => (int)SharedMappingFuncs.GetOptionset<ApplicationOriginTypeEnum, ApplicationOriginOptionSet>(s.ApplicationOriginTypeCode)))
.ForMember(d => d.spd_origin, opt => opt.MapFrom(s => (int?)SharedMappingFuncs.GetOptionset<ApplicationOriginTypeEnum, ApplicationOriginOptionSet>(s.ApplicationOriginTypeCode)))
.ForMember(d => d.spd_payer, opt => opt.MapFrom(s => (int)PayerPreferenceOptionSet.Organization))
.ForMember(d => d.spd_dateofbirth, opt => opt.MapFrom(s => SharedMappingFuncs.GetDateFromDateOnly(s.DateOfBirth)))
.ForMember(d => d.spd_sex, opt => opt.MapFrom(s => SharedMappingFuncs.GetGender(s.GenderCode)))
Expand All @@ -85,6 +85,7 @@ public Mappings()
.ForMember(d => d.spd_hasdriverslicence, opt => opt.MapFrom(s => SharedMappingFuncs.GetYesNo(s.HasBcDriversLicence)))
.ForMember(d => d.statecode, opt => opt.MapFrom(s => DynamicsConstants.StateCode_Active))
.ForMember(d => d.spd_submittedon, opt => opt.Ignore())
.ForMember(d => d.spd_licencefee, opt => opt.MapFrom(s => 0))
.ForMember(d => d.spd_declaration, opt => opt.MapFrom(s => s.AgreeToCompleteAndAccurate))
.ForMember(d => d.spd_declarationdate, opt => opt.MapFrom(s => SharedMappingFuncs.GetDeclarationDate(s.AgreeToCompleteAndAccurate)))
.ForMember(d => d.spd_consent, opt => opt.MapFrom(s => s.AgreeToCompleteAndAccurate))
Expand Down
2 changes: 1 addition & 1 deletion src/Spd.Resource.Repository/SharedMappingFuncs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ internal static IEnumerable<UploadedDocumentEnum> GetUploadedDocumentEnums(strin
}
internal static bool GetIdentityConfirmed(ApplicationOriginTypeEnum? origin, ApplicationTypeEnum type)
{
bool isNotPortal = origin != ApplicationOriginTypeEnum.Portal;
bool isNotPortal = origin == null || origin != ApplicationOriginTypeEnum.Portal;
bool isNewOrRenewal = type == ApplicationTypeEnum.New ||
type == ApplicationTypeEnum.Renewal;

Expand Down

0 comments on commit 5316258

Please sign in to comment.