Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into feat/DTFS2-7498/fetch-eligibility…
Browse files Browse the repository at this point in the history
…-critieria-to-display

# Conflicts:
#	dtfs-central-api/src/services/portal/facility-amendment.upsertPortalFacilityAmendmentDraft.service.test.ts
#	gef-ui/test-helpers/mock-amendment.ts
#	libs/common/src/test-helpers/mock-data-backend/portal-facility-amendment.ts
#	libs/common/src/types/mongo-db-models/tfm-facilities.ts
  • Loading branch information
BethThomas141 committed Jan 20, 2025
2 parents bec8c35 + 4f08239 commit 8bd62fc
Show file tree
Hide file tree
Showing 101 changed files with 685 additions and 323 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { MONGO_DB_COLLECTIONS, AMENDMENT_STATUS, CURRENCY } = require('@ukef/dtfs2-common');
const { MONGO_DB_COLLECTIONS, TFM_AMENDMENT_STATUS, CURRENCY } = require('@ukef/dtfs2-common');
const { generateTfmAuditDetails, generatePortalAuditDetails } = require('@ukef/dtfs2-common/change-stream');
const { withMongoIdPathParameterValidationTests } = require('@ukef/dtfs2-common/test-cases-backend');
const wipeDB = require('../../../wipeDB');
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('GET TFM amendments', () => {
const { body: bodyPostResponse } = await testApi
.post({ auditDetails: generateTfmAuditDetails(MOCK_TFM_USER._id) })
.to(`/v1/tfm/facilities/${facilityId}/amendments`);
const updatePayload = { status: AMENDMENT_STATUS.IN_PROGRESS };
const updatePayload = { status: TFM_AMENDMENT_STATUS.IN_PROGRESS };
await testApi
.put({ payload: updatePayload, auditDetails: generateTfmAuditDetails(MOCK_TFM_USER._id) })
.to(`/v1/tfm/facilities/${facilityId}/amendments/${bodyPostResponse.amendmentId}`);
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('GET TFM amendments', () => {
const { body: bodyPostResponse } = await testApi
.post({ auditDetails: generateTfmAuditDetails(MOCK_TFM_USER._id) })
.to(`/v1/tfm/facilities/${facilityId}/amendments`);
const updatePayload = { status: AMENDMENT_STATUS.IN_PROGRESS };
const updatePayload = { status: TFM_AMENDMENT_STATUS.IN_PROGRESS };
await testApi
.put({ payload: updatePayload, auditDetails: generateTfmAuditDetails(MOCK_TFM_USER._id) })
.to(`/v1/tfm/facilities/${facilityId}/amendments/${bodyPostResponse.amendmentId}`);
Expand Down Expand Up @@ -207,7 +207,7 @@ describe('GET TFM amendments', () => {
} = await testApi.post({ auditDetails: generateTfmAuditDetails(MOCK_TFM_USER._id) }).to(`/v1/tfm/facilities/${facilityId}/amendments`);
await testApi
.put({
payload: { status: AMENDMENT_STATUS.COMPLETED },
payload: { status: TFM_AMENDMENT_STATUS.COMPLETED },
auditDetails: generateTfmAuditDetails(MOCK_TFM_USER._id),
})
.to(`/v1/tfm/facilities/${facilityId}/amendments/${amendmentId}`);
Expand All @@ -217,7 +217,7 @@ describe('GET TFM amendments', () => {
} = await testApi.post({ auditDetails: generateTfmAuditDetails(MOCK_TFM_USER._id) }).to(`/v1/tfm/facilities/${facilityId}/amendments`);
await testApi
.put({
payload: { status: AMENDMENT_STATUS.COMPLETED },
payload: { status: TFM_AMENDMENT_STATUS.COMPLETED },
auditDetails: generateTfmAuditDetails(MOCK_TFM_USER._id),
})
.to(`/v1/tfm/facilities/${facilityId}/amendments/${amendmentId2}`);
Expand Down Expand Up @@ -292,7 +292,7 @@ describe('GET TFM amendments', () => {
await testApi
.put({
payload: {
status: AMENDMENT_STATUS.COMPLETED,
status: TFM_AMENDMENT_STATUS.COMPLETED,
submittedByPim: true,
requireUkefApproval: false,
changeFacilityValue: true,
Expand Down Expand Up @@ -347,7 +347,7 @@ describe('GET TFM amendments', () => {
const { body: bodyPostResponse1 } = await testApi
.post({ auditDetails: generateTfmAuditDetails(MOCK_TFM_USER._id) })
.to(`/v1/tfm/facilities/${facilityId1}/amendments`);
const updatePayload1 = { status: AMENDMENT_STATUS.IN_PROGRESS };
const updatePayload1 = { status: TFM_AMENDMENT_STATUS.IN_PROGRESS };
await testApi
.put({ payload: updatePayload1, auditDetails: generateTfmAuditDetails(MOCK_TFM_USER._id) })
.to(`/v1/tfm/facilities/${facilityId1}/amendments/${bodyPostResponse1.amendmentId}`);
Expand All @@ -366,7 +366,7 @@ describe('GET TFM amendments', () => {
const { body: bodyPostResponse2 } = await testApi
.post({ auditDetails: generateTfmAuditDetails(MOCK_TFM_USER._id) })
.to(`/v1/tfm/facilities/${facilityId2}/amendments`);
const updatePayload2 = { status: AMENDMENT_STATUS.IN_PROGRESS };
const updatePayload2 = { status: TFM_AMENDMENT_STATUS.IN_PROGRESS };
await testApi
.put({ payload: updatePayload2, auditDetails: generateTfmAuditDetails(MOCK_TFM_USER._id) })
.to(`/v1/tfm/facilities/${facilityId2}/amendments/${bodyPostResponse2.amendmentId}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { MONGO_DB_COLLECTIONS, AUDIT_USER_TYPES, AMENDMENT_STATUS } = require('@ukef/dtfs2-common');
const { MONGO_DB_COLLECTIONS, AUDIT_USER_TYPES, TFM_AMENDMENT_STATUS } = require('@ukef/dtfs2-common');
const { generatePortalAuditDetails, generateTfmAuditDetails } = require('@ukef/dtfs2-common/change-stream');
const { withMongoIdPathParameterValidationTests } = require('@ukef/dtfs2-common/test-cases-backend');
const wipeDB = require('../../../wipeDB');
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('POST TFM amendments', () => {
.post({ auditDetails: generateTfmAuditDetails(MOCK_TFM_USER._id) })
.to(`/v1/tfm/facilities/${facilityId}/amendments`);

const updatePayload1 = { status: AMENDMENT_STATUS.IN_PROGRESS };
const updatePayload1 = { status: TFM_AMENDMENT_STATUS.IN_PROGRESS };
await testApi
.put({ payload: updatePayload1, auditDetails: generateTfmAuditDetails(MOCK_TFM_USER._id) })
.to(`/v1/tfm/facilities/${facilityId}/amendments/${bodyPostResponse1.amendmentId}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpStatusCode } from 'axios';
import { IsNull, Not } from 'typeorm';
import {
AMENDMENT_STATUS,
TFM_AMENDMENT_STATUS,
convertMillisecondsToSeconds,
FacilityUtilisationDataEntity,
FacilityUtilisationDataEntityMockBuilder,
Expand Down Expand Up @@ -399,7 +399,7 @@ describe(`POST ${BASE_URL}`, () => {
{
...aTfmFacilityAmendment(),
value: 350000,
status: AMENDMENT_STATUS.COMPLETED,
status: TFM_AMENDMENT_STATUS.COMPLETED,
// Effective dates are stored in unix epoch time in seconds not milliseconds.
effectiveDate: convertMillisecondsToSeconds(dateAfterReportPeriodEnd.getTime()),
// 365 days after report period end
Expand All @@ -408,7 +408,7 @@ describe(`POST ${BASE_URL}`, () => {
{
...aTfmFacilityAmendment(),
value: 300000,
status: AMENDMENT_STATUS.COMPLETED,
status: TFM_AMENDMENT_STATUS.COMPLETED,
// Effective dates are stored in unix epoch time in seconds not milliseconds.
effectiveDate: convertMillisecondsToSeconds(dateWithinReportPeriod.getTime()),
// 730 days after report period end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AMENDMENT_STATUS, convertMillisecondsToSeconds, TfmFacilityAmendment } from '@ukef/dtfs2-common';
import { TFM_AMENDMENT_STATUS, convertMillisecondsToSeconds, TfmFacilityAmendment } from '@ukef/dtfs2-common';
import { addDays, subDays } from 'date-fns';
import { aCompletedTfmFacilityAmendment, aTfmFacilityAmendment } from '../../../test-helpers';
import { filterAndSortCompletedEffectiveAmendments } from './filter-and-sort-completed-effective-amendments';
Expand All @@ -24,10 +24,10 @@ describe('filter-and-sort-completed-effective-amendments', () => {
const now = new Date();
const beforeNow = subDays(now, 1);

const aCompletedAmendment = { ...aTfmFacilityAmendment(), status: AMENDMENT_STATUS.COMPLETED, effectiveDate: beforeNow.getTime() };
const aCompletedAmendment = { ...aTfmFacilityAmendment(), status: TFM_AMENDMENT_STATUS.COMPLETED, effectiveDate: beforeNow.getTime() };
const amendments: TfmFacilityAmendment[] = [
{ ...aTfmFacilityAmendment(), status: AMENDMENT_STATUS.IN_PROGRESS, effectiveDate: beforeNow.getTime() },
{ ...aTfmFacilityAmendment(), status: AMENDMENT_STATUS.NOT_STARTED, effectiveDate: beforeNow.getTime() },
{ ...aTfmFacilityAmendment(), status: TFM_AMENDMENT_STATUS.IN_PROGRESS, effectiveDate: beforeNow.getTime() },
{ ...aTfmFacilityAmendment(), status: TFM_AMENDMENT_STATUS.NOT_STARTED, effectiveDate: beforeNow.getTime() },
aCompletedAmendment,
];

Expand Down Expand Up @@ -113,13 +113,13 @@ describe('filter-and-sort-completed-effective-amendments', () => {
// Arrange
const firstEffectiveAmendment = {
...aTfmFacilityAmendment(),
status: AMENDMENT_STATUS.COMPLETED,
status: TFM_AMENDMENT_STATUS.COMPLETED,
effectiveDate: twoDaysBeforeLatestEffectiveDate,
};

const secondEffectiveAmendment = {
...aTfmFacilityAmendment(),
status: AMENDMENT_STATUS.COMPLETED,
status: TFM_AMENDMENT_STATUS.COMPLETED,
effectiveDate: oneDayBeforeLatestEffectiveDate,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AMENDMENT_STATUS, FacilityAmendment, isValidDate } from '@ukef/dtfs2-common';
import { TFM_AMENDMENT_STATUS, FacilityAmendment, isValidDate } from '@ukef/dtfs2-common';
import { isBefore } from 'date-fns';
import { orderBy } from 'lodash';
import { convertTimestampToDate } from '../convert-timestamp-to-date';
Expand All @@ -17,7 +17,7 @@ import { convertTimestampToDate } from '../convert-timestamp-to-date';
*/
export const filterAndSortCompletedEffectiveAmendments = (tfmFacilityAmendments: FacilityAmendment[], latestEffectiveDate: Date): FacilityAmendment[] => {
const filteredAmendments = tfmFacilityAmendments.filter(({ status, effectiveDate, updatedAt, amendmentId }) => {
if (status !== AMENDMENT_STATUS.COMPLETED) {
if (status !== TFM_AMENDMENT_STATUS.COMPLETED) {
return false;
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { amendmentsByStatus } from './amendments-by-status';
import { tfmAmendmentsByStatus } from './tfm-amendments-by-status';
import { amendmentsByFacilityId } from './amendments-by-facility-id';
import { amendmentsByDealId } from './amendments-by-deal-id';
import { amendmentsByFacilityIdAndStatus } from './amendments-by-facility-id-and-status';
import { amendmentsByDealIdAndStatus } from './amendments-by-deal-id-and-status';
import { tfmAmendmentsByFacilityIdAndStatus } from './tfm-amendments-by-facility-id-and-status';
import { tfmAmendmentsByDealIdAndStatus } from './tfm-amendments-by-deal-id-and-status';
import { latestCompletedTfmAmendmentByFacilityId } from './latest-completed-amendment-by-facility-id';
import { latestCompletedAmendmentByDealId } from './lastest-completed-amendment-by-deal-id';
import { allFacilitiesAndFacilityCount } from './all-facilities-and-facility-count';

export { AllFacilitiesAndFacilityCountAggregatePipelineOptions } from './all-facilities-and-facility-count';

export const aggregatePipelines = {
amendmentsByStatus,
tfmAmendmentsByStatus,
amendmentsByFacilityId,
amendmentsByDealId,
amendmentsByFacilityIdAndStatus,
amendmentsByDealIdAndStatus,
tfmAmendmentsByFacilityIdAndStatus,
tfmAmendmentsByDealIdAndStatus,
latestCompletedTfmAmendmentByFacilityId,
latestCompletedAmendmentByDealId,
allFacilitiesAndFacilityCount,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ObjectId, Document } from 'mongodb';
import { AMENDMENT_STATUS } from '@ukef/dtfs2-common';
import { TFM_AMENDMENT_STATUS } from '@ukef/dtfs2-common';

export const latestCompletedAmendmentByDealId = (dealId: string | ObjectId): Document[] => [
{ $match: { 'facilitySnapshot.dealId': { $eq: new ObjectId(dealId) } } },
{ $unwind: '$amendments' },
{ $match: { 'amendments.status': AMENDMENT_STATUS.COMPLETED } },
{ $match: { 'amendments.status': TFM_AMENDMENT_STATUS.COMPLETED } },
{ $sort: { 'amendments.updatedAt': -1, 'amendments.version': -1 } },
{ $project: { _id: false, amendments: true } },
{ $limit: 1 },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ObjectId, Document } from 'mongodb';
import { AMENDMENT_STATUS, AMENDMENT_TYPES } from '@ukef/dtfs2-common';
import { TFM_AMENDMENT_STATUS, AMENDMENT_TYPES } from '@ukef/dtfs2-common';

export const latestCompletedTfmAmendmentByFacilityId = (facilityId: string | ObjectId): Document[] => [
{ $match: { _id: { $eq: new ObjectId(facilityId) } } },
{ $unwind: '$amendments' },
{ $match: { 'amendments.status': { $eq: AMENDMENT_STATUS.COMPLETED }, 'amendments.type': { $ne: AMENDMENT_TYPES.PORTAL } } },
{ $match: { 'amendments.status': { $eq: TFM_AMENDMENT_STATUS.COMPLETED }, 'amendments.type': { $ne: AMENDMENT_TYPES.PORTAL } } },
{ $sort: { 'amendments.updatedAt': -1, 'amendments.version': -1 } },
{ $project: { _id: false, amendments: true } },
{ $limit: 1 },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ObjectId, Document } from 'mongodb';
import { AMENDMENT_TYPES, TfmAmendmentStatus } from '@ukef/dtfs2-common';

/**
* Generate aggregate pipeline to get tfm amendments by deal id and status
* @param dealId - the deal id
* @param status - the tfm amendment status
* @returns aggregate pipeline to get tfm amendments by deal id and status
*/
export const tfmAmendmentsByDealIdAndStatus = (dealId: string | ObjectId, status: TfmAmendmentStatus): Document[] => [
{ $match: { 'facilitySnapshot.dealId': { $eq: new ObjectId(dealId) } } },
{
$addFields: {
'amendments.ukefFacilityId': '$facilitySnapshot.ukefFacilityId',
},
},
{ $unwind: '$amendments' },
{ $match: { 'amendments.status': { $eq: status }, 'amendments.type': { $ne: AMENDMENT_TYPES.PORTAL } } },
{ $project: { _id: false, amendments: true } },
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ObjectId, Document } from 'mongodb';
import { AMENDMENT_TYPES, TfmAmendmentStatus } from '@ukef/dtfs2-common';

/**
* Generate aggregate pipeline to get tfm amendments by facility id and status
* @param facilityId - the facility id
* @param status - the tfm amendment status
* @returns aggregate pipeline to get tfm amendments by facility id and status
*/
export const tfmAmendmentsByFacilityIdAndStatus = (facilityId: string | ObjectId, status: TfmAmendmentStatus): Document[] => [
{ $match: { _id: { $eq: new ObjectId(facilityId) } } },
{ $unwind: '$amendments' },
{ $match: { 'amendments.status': { $eq: status }, 'amendments.type': { $ne: AMENDMENT_TYPES.PORTAL } } },
{ $project: { _id: false, amendments: true } },
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Document } from 'mongodb';
import { AMENDMENT_TYPES, TfmAmendmentStatus } from '@ukef/dtfs2-common';

/**
* Generate aggregate pipeline to get tfm amendments by status
* @param status - the tfm amendment status
* @returns aggregate pipeline to get tfm amendments by status
*/
export const tfmAmendmentsByStatus = (status: TfmAmendmentStatus): Document[] => [
{ $unwind: '$amendments' },
{ $match: { 'amendments.status': { $eq: status }, 'amendments.type': { $ne: AMENDMENT_TYPES.PORTAL } } },
{ $project: { _id: false, amendments: true } },
];
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import {
AuditDetails,
TfmFacility,
FacilityAmendment,
AmendmentStatus,
TfmAmendmentStatus,
FacilityNotFoundError,
AmendmentNotFoundError,
AMENDMENT_TYPES,
AMENDMENT_STATUS,
PortalFacilityAmendment,
GEF_FACILITY_TYPE,
TfmFacilityAmendment,
FacilityAmendmentWithUkefId,
PORTAL_AMENDMENT_STATUS,
} from '@ukef/dtfs2-common';
import { deleteMany, generateAuditDatabaseRecordFromAuditDetails } from '@ukef/dtfs2-common/change-stream';
import { mongoDbClient } from '../../drivers/db-client';
Expand Down Expand Up @@ -128,14 +128,14 @@ export class TfmFacilitiesRepo {
}

/**
* Find amendments by the amendment status
* @param status - The amendment status
* Find TFM amendments by the amendment status
* @param status - The tfm amendment status
* @returns The found amendments
*/
public static async findAmendmentsByStatus(status: AmendmentStatus): Promise<Document[]> {
public static async findTfmAmendmentsByStatus(status: TfmAmendmentStatus): Promise<Document[]> {
const collection = await this.getCollection();
return await collection
.aggregate(aggregatePipelines.amendmentsByStatus(status))
.aggregate(aggregatePipelines.tfmAmendmentsByStatus(status))
.map<Document>((doc) => doc.amendments as Document)
.toArray();
}
Expand All @@ -154,15 +154,15 @@ export class TfmFacilitiesRepo {
}

/**
* Finds amendments by the facility id and status
* Finds tfm amendments by the facility id and status
* @param facilityId - The facility id
* @param status - The amendment status
* @param status - The TFM amendment status
* @returns The found amendments
*/
public static async findAmendmentsByFacilityIdAndStatus(facilityId: string | ObjectId, status: AmendmentStatus): Promise<FacilityAmendment[]> {
public static async findTfmAmendmentsByFacilityIdAndStatus(facilityId: string | ObjectId, status: TfmAmendmentStatus): Promise<FacilityAmendment[]> {
const collection = await this.getCollection();
return await collection
.aggregate(aggregatePipelines.amendmentsByFacilityIdAndStatus(facilityId, status))
.aggregate(aggregatePipelines.tfmAmendmentsByFacilityIdAndStatus(facilityId, status))
.map<FacilityAmendment>((doc) => doc.amendments as FacilityAmendment)
.toArray();
}
Expand Down Expand Up @@ -214,15 +214,15 @@ export class TfmFacilitiesRepo {
}

/**
* Finds amendments by the deal id and status
* Finds tfm amendments by the deal id and status
* @param dealId - The deal id
* @param status - The amendment status
* @param status - The tfm amendment status
* @returns The found amendments
*/
public static async findAmendmentsByDealIdAndStatus(dealId: string | ObjectId, status: AmendmentStatus): Promise<Document[]> {
public static async findTfmAmendmentsByDealIdAndStatus(dealId: string | ObjectId, status: TfmAmendmentStatus): Promise<Document[]> {
const collection = await this.getCollection();
return await collection
.aggregate(aggregatePipelines.amendmentsByDealIdAndStatus(dealId, status))
.aggregate(aggregatePipelines.tfmAmendmentsByDealIdAndStatus(dealId, status))
.map<Document>((doc) => doc.amendments as Document)
.toArray();
}
Expand Down Expand Up @@ -332,7 +332,7 @@ export class TfmFacilitiesRepo {

const removeDraftAmendmentsFilter: UpdateFilter<TfmFacility> = {
$pull: {
amendments: { type: AMENDMENT_TYPES.PORTAL, status: { $ne: AMENDMENT_STATUS.COMPLETED } },
amendments: { type: AMENDMENT_TYPES.PORTAL, status: { $eq: PORTAL_AMENDMENT_STATUS.DRAFT } },
},
$set: { auditRecord: generateAuditDatabaseRecordFromAuditDetails(auditDetails) },
};
Expand Down
Loading

0 comments on commit 8bd62fc

Please sign in to comment.