Skip to content

Commit 9c8b37d

Browse files
[SPDBT-3008] cm-crc create with invite (#1370)
# Description This PR includes the following proposed change(s): - added InviteId and get invite in create - make Invite record status `completed` after application creation --------- Co-authored-by: peggy-quartech <peggy.zhang@quartech.com>
1 parent 592cde7 commit 9c8b37d

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

src/Spd.Manager.Licence.UnitTest/ControllingMemberCrcAppManagerTest.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using AutoMapper;
22
using Moq;
33
using Spd.Manager.Licence;
4+
using Spd.Resource.Repository.ApplicationInvite;
45
using Spd.Resource.Repository.ControllingMemberCrcApplication;
56
using Spd.Resource.Repository.Document;
67
using Spd.Resource.Repository.LicApp;
@@ -21,6 +22,8 @@ public class ControllingMemberCrcAppManagerTests
2122
private readonly Mock<ITransientFileStorageService> _transientFileServiceMock;
2223
private readonly Mock<IControllingMemberCrcRepository> _controllingMemberCrcRepositoryMock;
2324
private readonly Mock<ILicAppRepository> _licAppRepositoryMock;
25+
private readonly Mock<IApplicationInviteRepository> _applicationInviteRepositoryMock;
26+
2427
private ControllingMemberCrcAppManager sut;
2528

2629
public ControllingMemberCrcAppManagerTests()
@@ -33,6 +36,7 @@ public ControllingMemberCrcAppManagerTests()
3336
_transientFileServiceMock = new Mock<ITransientFileStorageService>();
3437
_controllingMemberCrcRepositoryMock = new Mock<IControllingMemberCrcRepository>();
3538
_licAppRepositoryMock = new Mock<ILicAppRepository>();
39+
_applicationInviteRepositoryMock = new Mock<IApplicationInviteRepository>();
3640
var mapperConfig = new MapperConfiguration(x =>
3741
{
3842
x.AddProfile<Mappings>();
@@ -43,7 +47,7 @@ public ControllingMemberCrcAppManagerTests()
4347
_feeRepositoryMock.Object,
4448
_licenceRepositoryMock.Object,
4549
_mainFileServiceMock.Object,
46-
_transientFileServiceMock.Object, _controllingMemberCrcRepositoryMock.Object, _licAppRepositoryMock.Object);
50+
_transientFileServiceMock.Object, _controllingMemberCrcRepositoryMock.Object, _applicationInviteRepositoryMock.Object, _licAppRepositoryMock.Object);
4751
}
4852

4953
[Fact]

src/Spd.Manager.Licence/ControllingMemberCrcAppContract.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public record ControllingMemberCrcAppBase
4343
public bool? IsTreatedForMHC { get; set; }
4444
public Address? ResidentialAddress { get; set; }
4545
public Guid BizContactId { get; set; }
46+
public Guid InviteId { get; set; }
4647
}
4748

4849

src/Spd.Manager.Licence/ControllingMemberCrcAppManager.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@
1818
using Spd.Resource.Repository.LicApp;
1919
using Spd.Resource.Repository.PersonLicApplication;
2020
using Spd.Resource.Repository.Application;
21+
using Spd.Resource.Repository.ApplicationInvite;
22+
using Spd.Resource.Repository;
2123

2224
namespace Spd.Manager.Licence;
2325
internal class ControllingMemberCrcAppManager :
2426
LicenceAppManagerBase,
2527
IRequestHandler<ControllingMemberCrcAppNewCommand, ControllingMemberCrcAppCommandResponse>,
28+
IRequestHandler<ControllingMemberCrcUpsertCommand, ControllingMemberCrcAppCommandResponse>,
29+
IRequestHandler<ControllingMemberCrcSubmitCommand, ControllingMemberCrcAppCommandResponse>,
30+
IRequestHandler<GetControllingMemberCrcApplicationQuery, ControllingMemberCrcAppResponse>,
2631
IControllingMemberCrcAppManager
2732
{
2833
private readonly IControllingMemberCrcRepository _controllingMemberCrcRepository;
34+
private readonly IApplicationInviteRepository _applicationInviteRepository;
2935

3036
public ControllingMemberCrcAppManager(IMapper mapper,
3137
IDocumentRepository documentRepository,
@@ -34,6 +40,7 @@ public ControllingMemberCrcAppManager(IMapper mapper,
3440
IMainFileStorageService mainFileService,
3541
ITransientFileStorageService transientFileService,
3642
IControllingMemberCrcRepository controllingMemberCrcRepository,
43+
IApplicationInviteRepository applicationInviteRepository,
3744
ILicAppRepository licAppRepository) : base(
3845
mapper,
3946
documentRepository,
@@ -44,10 +51,24 @@ public ControllingMemberCrcAppManager(IMapper mapper,
4451
licAppRepository)
4552
{
4653
_controllingMemberCrcRepository = controllingMemberCrcRepository;
54+
_applicationInviteRepository = applicationInviteRepository;
4755
}
4856
#region anonymous new
4957
public async Task<ControllingMemberCrcAppCommandResponse> Handle(ControllingMemberCrcAppNewCommand cmd, CancellationToken ct)
5058
{
59+
ApplicationInviteResult? invite = null;
60+
//check if invite is still valid
61+
if (cmd.ControllingMemberCrcAppSubmitRequest?.InviteId != null)
62+
{
63+
var invites = await _applicationInviteRepository.QueryAsync(
64+
new ApplicationInviteQuery()
65+
{
66+
FilterBy = new AppInviteFilterBy(null, null, AppInviteId: cmd.ControllingMemberCrcAppSubmitRequest.InviteId)
67+
}, ct);
68+
invite = invites.ApplicationInvites.FirstOrDefault();
69+
if (invite != null && (invite.Status == ApplicationInviteStatusEnum.Completed || invite.Status == ApplicationInviteStatusEnum.Cancelled || invite.Status == ApplicationInviteStatusEnum.Expired))
70+
throw new ArgumentException("Invalid Invite status.");
71+
}
5172

5273
ControllingMemberCrcAppSubmitRequest request = cmd.ControllingMemberCrcAppSubmitRequest;
5374
ValidateFilesForNewApp(cmd);
@@ -60,8 +81,19 @@ public async Task<ControllingMemberCrcAppCommandResponse> Handle(ControllingMemb
6081

6182
await UploadNewDocsAsync(request.DocumentExpiredInfos, cmd.LicAppFileInfos, response.ControllingMemberCrcAppId, response.ContactId, null, null, null, null, null, ct);
6283

84+
//
6385
await _licAppRepository.CommitLicenceApplicationAsync(response.ControllingMemberCrcAppId, ApplicationStatusEnum.Submitted, ct);
6486

87+
//inactivate invite
88+
if (cmd.ControllingMemberCrcAppSubmitRequest?.InviteId != null)
89+
{
90+
await _applicationInviteRepository.ManageAsync(
91+
new ApplicationInviteUpdateCmd()
92+
{
93+
ApplicationInviteId = (Guid)cmd.ControllingMemberCrcAppSubmitRequest.InviteId,
94+
ApplicationInviteStatusEnum = ApplicationInviteStatusEnum.Completed
95+
}, ct);
96+
}
6597
return new ControllingMemberCrcAppCommandResponse
6698
{
6799
ControllingMemberAppId = response.ControllingMemberCrcAppId,

src/Spd.Resource.Repository/ControllingMemberCrcApplication/ControllingMemberCrcRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public async Task<ControllingMemberCrcApplicationCmdResp> SaveControllingMemberC
159159
SharedRepositoryFuncs.LinkTeam(_context, DynamicsConstants.Licensing_Client_Service_Team_Guid, app);
160160

161161
//link to bizContact
162-
_context.SetLink(app, nameof(spd_application.spd_businesscontact_spd_application), bizContact);
162+
_context.AddLink(bizContact, nameof(spd_application.spd_businesscontact_spd_application), app);
163163
}
164164

165165
await _context.SaveChangesAsync();

0 commit comments

Comments
 (0)