Skip to content

Commit

Permalink
feat(Agreement): added agreementStatus and agreementView (#391)
Browse files Browse the repository at this point in the history
Refs: CPLP-3469
Reviewed-By: Phil Schneider <[email protected]>
  • Loading branch information
VPrasannaK94 authored Jan 2, 2024
1 parent 387165c commit 2813346
Show file tree
Hide file tree
Showing 26 changed files with 9,563 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public async Task CreateCompanyRoleAndConsentAgreementDetailsAsync(IEnumerable<C
}

var agreementAssignedRoleData = await companyRepositories.GetAgreementAssignedRolesDataAsync(companyRoleConsentDetails.Select(x => x.CompanyRole))
.PreSortedGroupBy(x => x.CompanyRoleId, x => x.AgreementId)
.PreSortedGroupBy(x => x.CompanyRoleId, x => x.agreementStatusData)
.ToDictionaryAsync(g => g.Key, g => g.AsEnumerable()).ConfigureAwait(false);

var joined = companyRoleConsentDetails
Expand All @@ -195,9 +195,9 @@ public async Task CreateCompanyRoleAndConsentAgreementDetailsAsync(IEnumerable<C
CompanyRoleId: details.CompanyRole,
AllActiveAgreements: details.Agreements.All(x => x.ConsentStatus == ConsentStatusId.ACTIVE),
AllInActiveAgreements: details.Agreements.All(x => x.ConsentStatus == ConsentStatusId.INACTIVE),
Agreements: details.Agreements,
MissingAgreementIds: data.Value.Except(details.Agreements.Where(x => x.ConsentStatus == ConsentStatusId.ACTIVE).Select(x => x.AgreementId)),
ExtraAgreementIds: details.Agreements.ExceptBy(data.Value, x => x.AgreementId).Select(x => x.AgreementId)))
Agreements: details.Agreements.ExceptBy(data.Value.Where(x => x.AgreementStatusId == AgreementStatusId.INACTIVE).Select(x => x.AgreementId), x => x.AgreementId),
MissingAgreementIds: data.Value.Select(x => x.AgreementId).Except(details.Agreements.Where(x => x.ConsentStatus == ConsentStatusId.ACTIVE).Select(x => x.AgreementId)),
ExtraAgreementIds: details.Agreements.ExceptBy(data.Value.Select(x => x.AgreementId), x => x.AgreementId).Select(x => x.AgreementId)))
.ToList();

var missing = joined.Where(x => x.MissingAgreementIds.Any() && !x.AllInActiveAgreements);
Expand Down
2 changes: 1 addition & 1 deletion src/maintenance/Maintenance.App/BatchDeleteService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
.ConfigureAwait(false);
_logger.LogInformation("Cleaning up {DocumentCount} Documents and {OfferIdCount} OfferAssignedDocuments", documentData.Count, documentData.SelectMany(x => x.OfferIds).Count());

var agreementsToDeleteDocumentId = documentData.SelectMany(data => data.AgreementIds.Select(agreementId => new Agreement(agreementId, default, null!, default) { DocumentId = data.DocumentId })).ToList();
var agreementsToDeleteDocumentId = documentData.SelectMany(data => data.AgreementIds.Select(agreementId => new Agreement(agreementId, default, null!, default, default, default) { DocumentId = data.DocumentId })).ToList();
dbContext.Agreements.AttachRange(agreementsToDeleteDocumentId);
agreementsToDeleteDocumentId.ForEach(agreement => agreement.DocumentId = null);
dbContext.OfferAssignedDocuments.RemoveRange(documentData.SelectMany(data => data.OfferIds.Select(offerId => new OfferAssignedDocument(offerId, data.DocumentId))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ IEnumerable<ConsentAgreementData> Agreements
public record ConsentAgreementData(Guid AgreementId, string AgreementName, Guid? DocumentId, ConsentStatusId ConsentStatus, string? AgreementLink);

public record ConsentStatusDetails(Guid ConsentId, Guid AgreementId, ConsentStatusId ConsentStatusId);

public record AgreementStatusData(Guid AgreementId, AgreementStatusId AgreementStatusId);
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public IAsyncEnumerable<AgreementData> GetOfferAgreementDataForOfferId(Guid offe
public IAsyncEnumerable<AgreementDocumentData> GetAgreementsForCompanyRolesUntrackedAsync() =>
_context.Agreements
.AsNoTracking()
.Where(agreement => agreement.AgreementAssignedCompanyRoles.Any())
.Where(agreement => agreement.AgreementAssignedCompanyRoles.Any() && agreement.AgreementStatusId == AgreementStatusId.ACTIVE)
.Select(agreement => new AgreementDocumentData(
agreement.Id,
agreement.Name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ public IAsyncEnumerable<CompanyRoleConsentData> GetCompanyRoleAndConsentAgreemen
companyRole.CompanyRoleDescriptions.SingleOrDefault(lc => lc.LanguageShortName == languageShortName)!.Description,
companyRole.CompanyAssignedRoles.Any(assigned => assigned.CompanyId == companyId),
companyRole.AgreementAssignedCompanyRoles
.Where(assigned => assigned.Agreement!.AgreementStatusId == AgreementStatusId.ACTIVE)
.Select(assigned => new ConsentAgreementData(
assigned.AgreementId,
assigned.Agreement!.Name,
Expand Down Expand Up @@ -265,12 +266,12 @@ public IAsyncEnumerable<CompanyRoleConsentData> GetCompanyRoleAndConsentAgreemen
.SingleOrDefaultAsync();

/// <inheritdoc />
public IAsyncEnumerable<(Guid AgreementId, CompanyRoleId CompanyRoleId)> GetAgreementAssignedRolesDataAsync(IEnumerable<CompanyRoleId> companyRoleIds) =>
public IAsyncEnumerable<(AgreementStatusData agreementStatusData, CompanyRoleId CompanyRoleId)> GetAgreementAssignedRolesDataAsync(IEnumerable<CompanyRoleId> companyRoleIds) =>
_context.AgreementAssignedCompanyRoles
.Where(assigned => companyRoleIds.Contains(assigned.CompanyRoleId))
.OrderBy(assigned => assigned.CompanyRoleId)
.Select(assigned => new ValueTuple<Guid, CompanyRoleId>(
assigned.AgreementId,
.Select(assigned => new ValueTuple<AgreementStatusData, CompanyRoleId>(
new AgreementStatusData(assigned.AgreementId, assigned.Agreement!.AgreementStatusId),
assigned.CompanyRoleId))
.AsAsyncEnumerable();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ public void RemoveCompanyAssignedRoles(Guid companyId, IEnumerable<CompanyRoleId
application.Company!.Consents.Select(c => new ConsentData(c.Id, c.ConsentStatusId, c.AgreementId))))
.SingleOrDefaultAsync();

public IAsyncEnumerable<(CompanyRoleId CompanyRoleId, IEnumerable<Guid> AgreementIds)> GetAgreementAssignedCompanyRolesUntrackedAsync(IEnumerable<CompanyRoleId> companyRoleIds) =>
public IAsyncEnumerable<(CompanyRoleId CompanyRoleId, IEnumerable<AgreementStatusData> AgreementStatusData)> GetAgreementAssignedCompanyRolesUntrackedAsync(IEnumerable<CompanyRoleId> companyRoleIds) =>
_dbContext.CompanyRoles
.AsNoTracking()
.Where(companyRole => companyRole.CompanyRoleRegistrationData!.IsRegistrationRole && companyRoleIds.Contains(companyRole.Id))
.Select(companyRole => new ValueTuple<CompanyRoleId, IEnumerable<Guid>>(
.Select(companyRole => new ValueTuple<CompanyRoleId, IEnumerable<AgreementStatusData>>(
companyRole.Id,
companyRole.AgreementAssignedCompanyRoles!.Select(agreementAssignedCompanyRole => agreementAssignedCompanyRole.AgreementId)
companyRole.AgreementAssignedCompanyRoles!
.Select(agreementAssignedCompanyRole => new AgreementStatusData(
agreementAssignedCompanyRole.AgreementId,
agreementAssignedCompanyRole.Agreement!.AgreementStatusId
))
)).AsAsyncEnumerable();

public Task<CompanyRoleAgreementConsents?> GetCompanyRoleAgreementConsentStatusUntrackedAsync(Guid applicationId, Guid companyId) =>
Expand All @@ -76,7 +80,7 @@ public void RemoveCompanyAssignedRoles(Guid companyId, IEnumerable<CompanyRoleId
company.CompanyApplications.Any(application => application.Id == applicationId))
.Select(company => new CompanyRoleAgreementConsents(
company.CompanyAssignedRoles.Select(companyAssignedRole => companyAssignedRole.CompanyRoleId),
company.Consents.Where(consent => consent.ConsentStatusId == ConsentStatusId.ACTIVE).Select(consent => new AgreementConsentStatus(
company.Consents.Where(consent => consent.ConsentStatusId == ConsentStatusId.ACTIVE && consent.Agreement!.AgreementStatusId == AgreementStatusId.ACTIVE).Select(consent => new AgreementConsentStatus(
consent.AgreementId,
consent.ConsentStatusId
)))).SingleOrDefaultAsync();
Expand All @@ -94,7 +98,7 @@ public async IAsyncEnumerable<CompanyRoleData> GetCompanyRoleAgreementsUntracked
ShortName = description.LanguageShortName,
Description = description.Description
}),
Agreements = companyRole.AgreementAssignedCompanyRoles.Select(agreementAssignedCompanyRole => agreementAssignedCompanyRole.AgreementId)
Agreements = companyRole.AgreementAssignedCompanyRoles.Where(agreementAssignedCompanyRole => agreementAssignedCompanyRole.Agreement!.AgreementStatusId == AgreementStatusId.ACTIVE).Select(agreementAssignedCompanyRole => agreementAssignedCompanyRole.AgreementId)
})
.AsAsyncEnumerable())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public interface ICompanyRepository
/// </summary>
/// <param name="companyRoleIds">Id of the CompanyRole</param>
/// <returns>Returns the AgreementAssignedCompanyRoles Data</returns>
IAsyncEnumerable<(Guid AgreementId, CompanyRoleId CompanyRoleId)> GetAgreementAssignedRolesDataAsync(IEnumerable<CompanyRoleId> companyRoleIds);
IAsyncEnumerable<(AgreementStatusData agreementStatusData, CompanyRoleId CompanyRoleId)> GetAgreementAssignedRolesDataAsync(IEnumerable<CompanyRoleId> companyRoleIds);

/// <summary>
/// Gets the the CompanyStatus Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface ICompanyRolesRepository
void CreateCompanyAssignedRoles(Guid companyId, IEnumerable<CompanyRoleId> companyRoleIds);
void RemoveCompanyAssignedRoles(Guid companyId, IEnumerable<CompanyRoleId> companyRoleIds);
Task<CompanyRoleAgreementConsentData?> GetCompanyRoleAgreementConsentDataAsync(Guid applicationId);
IAsyncEnumerable<(CompanyRoleId CompanyRoleId, IEnumerable<Guid> AgreementIds)> GetAgreementAssignedCompanyRolesUntrackedAsync(IEnumerable<CompanyRoleId> companyRoleIds);
IAsyncEnumerable<(CompanyRoleId CompanyRoleId, IEnumerable<AgreementStatusData> AgreementStatusData)> GetAgreementAssignedCompanyRolesUntrackedAsync(IEnumerable<CompanyRoleId> companyRoleIds);
Task<CompanyRoleAgreementConsents?> GetCompanyRoleAgreementConsentStatusUntrackedAsync(Guid applicationId, Guid companyId);
IAsyncEnumerable<CompanyRoleData> GetCompanyRoleAgreementsUntrackedAsync();
IAsyncEnumerable<CompanyRolesDetails> GetCompanyRolesAsync(string? languageShortName = null);
Expand Down
Loading

0 comments on commit 2813346

Please sign in to comment.