Skip to content

Commit

Permalink
fix issue for get sole proprietor swl lic photo (#1568)
Browse files Browse the repository at this point in the history
# Description

This PR includes the following proposed change(s):

- spdbt-3177 : fix issue for get sole proprietor swl lic photo
  • Loading branch information
esdd1995 authored Oct 17, 2024
2 parents 28cb37b + a3454cf commit bf00173
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Spd.Manager.Licence/BizLicAppContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public record BizLicAppResponse : BizLicenceApp
public Guid? ExpiredLicenceId { get; set; }
public bool? HasExpiredLicence { get; set; }
public bool? ApplicantIsBizManager { get; set; }
public ApplicationOriginTypeCode SoleProprietorSWLAppOriginTypeCode { get; set; }

// Contains branding, insurance, registrar, security dog certificate and BC report documents
public IEnumerable<Document>? DocumentInfos { get; set; }
Expand All @@ -94,6 +93,7 @@ public abstract record BizLicenceApp : LicenceAppBase
public bool? AgreeToCompleteAndAccurate { get; set; }
public bool? ApplicantIsBizManager { get; set; }
public Guid? SoleProprietorSWLAppId { get; set; } //for swl apply for sole proprietor, they need to input swl app id here.
public ApplicationOriginTypeCode? SoleProprietorSWLAppOriginTypeCode { get; set; }
public Guid? SubmittedByPortalUserId { get; set; }
}

Expand Down
10 changes: 9 additions & 1 deletion src/Spd.Manager.Licence/LicenceAppManagerBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AutoMapper;
using Spd.Manager.Shared;
using Spd.Resource.Repository;
using Spd.Resource.Repository.Application;
using Spd.Resource.Repository.Document;
Expand Down Expand Up @@ -39,7 +40,12 @@ public LicenceAppManagerBase(IMapper mapper,
_licAppRepository = licAppRepository;
}

protected async Task<decimal> CommitApplicationAsync(LicenceAppBase licAppBase, Guid licenceAppId, CancellationToken ct, bool HasSwl90DayLicence = false, Guid? companionAppId = null)
protected async Task<decimal> CommitApplicationAsync(LicenceAppBase licAppBase,
Guid licenceAppId,
CancellationToken ct,
bool HasSwl90DayLicence = false,
Guid? companionAppId = null,
ApplicationOriginTypeCode? companionAppOrigin = null)
{
//if payment price is 0, directly set to Submitted, or PaymentPending
var price = await _feeRepository.QueryAsync(new LicenceFeeQry()
Expand All @@ -66,6 +72,8 @@ protected async Task<decimal> CommitApplicationAsync(LicenceAppBase licAppBase,
//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)
{
if (companionAppOrigin == ApplicationOriginTypeCode.Portal) //only authenticated swl save file in transient storage
await MoveFilesAsync((Guid)companionAppId, ct);
await _licAppRepository.CommitLicenceApplicationAsync((Guid)companionAppId, ApplicationStatusEnum.PaymentPending, null, ct);
}
// Commit the main licence application
Expand Down
19 changes: 7 additions & 12 deletions src/Spd.Manager.Licence/LicenceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,17 @@ public async Task<IEnumerable<LicenceBasicResponse>> Handle(LicenceListQuery que
public async Task<FileResponse?> Handle(LicencePhotoQuery query, CancellationToken cancellationToken)
{
//find contact id through licenceId
LicenceListResp lic = await _licenceRepository.QueryAsync(new LicenceQry() { LicenceId = query.LicenceId }, cancellationToken);
Guid? applicantId = lic.Items.FirstOrDefault()?.LicenceHolderId;
if (applicantId == null)
LicenceResp lic = await _licenceRepository.GetAsync(query.LicenceId, cancellationToken);
if (lic == null)
{
throw new ApiException(HttpStatusCode.BadRequest, "cannot find the licence holder.");
throw new ApiException(HttpStatusCode.BadRequest, "cannot find the licence.");
}
if (lic.PhotoDocumentUrlId == null)
throw new ApiException(HttpStatusCode.BadRequest, "the licence does not have photo");

DocumentQry qry = new()
{
ApplicantId = applicantId,
FileType = Enum.Parse<DocumentTypeEnum>(DocumentTypeEnum.Photograph.ToString()),
};
DocumentListResp docList = await _documentRepository.QueryAsync(qry, cancellationToken);
if (docList == null || !docList.Items.Any())
DocumentResp? docUrl = await _documentRepository.GetAsync((Guid)lic.PhotoDocumentUrlId, cancellationToken);
if (docUrl == null)
return new FileResponse();
var docUrl = docList.Items.OrderByDescending(f => f.UploadedDateTime).FirstOrDefault();

if (docUrl != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Spd.Resource.Repository/Licence/LicenceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task<LicenceListResp> QueryAsync(LicenceQry qry, CancellationToken
lics = lics.Where(d => d.statecode != DynamicsConstants.StateCode_Inactive);

if (qry.IncludeInactive)
lics = lics.Where(d => d.statuscode != (int)LicenceStatusOptionSet.Suspended);
lics = lics.Where(d => d.statuscode != (int)LicenceStatusOptionSet.Inactive && d.statuscode != (int)LicenceStatusOptionSet.Suspended);

if (qry.LicenceId != null)
{
Expand Down

0 comments on commit bf00173

Please sign in to comment.