Skip to content

Commit

Permalink
chore: adjust database query
Browse files Browse the repository at this point in the history
Refs: CPLP-2986
  • Loading branch information
Phil91 committed Jul 29, 2023
1 parent e0cca89 commit 6af5f97
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,17 @@ public InvitationRepository(PortalDbContext dbContext)
{
_dbContext = dbContext;
}

public IAsyncEnumerable<InvitedUserDetail> GetInvitedUserDetailsUntrackedAsync(Guid applicationId) =>
_dbContext.Invitations
.Join(_dbContext.InvitationStatuses,
i => i.InvitationStatusId,
invitationStatus => invitationStatus.Id,
(i, invitationStatus) => new { Invitation = i, InvitationStatus = invitationStatus })
.Join(_dbContext.CompanyUsers,
i => i.Invitation.CompanyUserId,
cu => cu.Id,
(i, cu) => new { i.Invitation, i.InvitationStatus, CompanyUser = cu })
.Where(i => i.Invitation.CompanyApplicationId == applicationId && i.CompanyUser.Identity!.UserStatusId != UserStatusId.DELETED)
.Select(i => new InvitedUserDetail(
i.CompanyUser.Identity!.UserEntityId,
i.InvitationStatus.Id,
i.CompanyUser.Email))
.AsNoTracking()
.AsAsyncEnumerable();
.AsNoTracking()
.Where(invitation =>
invitation.CompanyApplicationId == applicationId &&
invitation.CompanyUser!.Identity!.UserStatusId != UserStatusId.DELETED)
.Select(invitation => new InvitedUserDetail(
invitation.CompanyUser!.Identity!.UserEntityId,
invitation.InvitationStatusId,
invitation.CompanyUser.Email))
.AsAsyncEnumerable();

public Task<Invitation?> GetInvitationStatusAsync(Guid companyUserId) =>
_dbContext.Invitations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ public async Task GetInvitedUserDetailsUntrackedAsync_WithValid_ReturnsExpected(

var result = await sut.GetInvitedUserDetailsUntrackedAsync(_applicationId).ToListAsync().ConfigureAwait(false);

result.Should().NotBeNull();
result.Should().HaveCount(2);
result.Should().Satisfy(
x => x.EmailId == "[email protected]" && x.InvitationStatus == InvitationStatusId.CREATED,
x => x.EmailId == "[email protected]" && x.InvitationStatus == InvitationStatusId.CREATED);
result.Should().HaveCount(2)
.And.Satisfy(
x => x.EmailId == "[email protected]" && x.InvitationStatus == InvitationStatusId.CREATED,
x => x.EmailId == "[email protected]" && x.InvitationStatus == InvitationStatusId.CREATED);
}

#region Setup
Expand Down

0 comments on commit 6af5f97

Please sign in to comment.