Skip to content

Commit

Permalink
chore(merge): merge release-1.5 to main (#2945)
Browse files Browse the repository at this point in the history
Co-authored-by: Abhi Markan <amarkan@ukexportfinance.gov.uk>
  • Loading branch information
abhi-markan and abhi-markan authored Mar 28, 2024
1 parent 1df56b9 commit ef51d86
Show file tree
Hide file tree
Showing 12 changed files with 778 additions and 140 deletions.
6 changes: 6 additions & 0 deletions portal-api/api-tests/fixtures/deal-fully-completed.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const deal = {
facilityStage: 'Issued',
hasBeenIssued: true,
ukefGuaranteeInMonths: '12',
coverDateConfirmed: true,
requestedCoverStartDate: nowDate.valueOf(),
'coverEndDate-day': format(nowPlusOneMonth, 'dd'),
'coverEndDate-month': format(nowPlusOneMonth, 'MM'),
Expand Down Expand Up @@ -81,6 +82,7 @@ const deal = {
facilityStage: 'Issued',
hasBeenIssued: true,
ukefGuaranteeInMonths: '12',
coverDateConfirmed: true,
requestedCoverStartDate: nowDate.valueOf(),
'coverEndDate-day': format(nowPlusOneMonth, 'dd'),
'coverEndDate-month': format(nowPlusOneMonth, 'MM'),
Expand Down Expand Up @@ -119,6 +121,7 @@ const deal = {
feeFrequency: 'Monthly',
dayCountBasis: '360',
issuedDate: nowDate.valueOf(),
coverDateConfirmed: true,
requestedCoverStartDate: nowDate.valueOf(),
'coverEndDate-day': format(nowPlusOneMonth, 'dd'),
'coverEndDate-month': format(nowPlusOneMonth, 'MM'),
Expand Down Expand Up @@ -227,6 +230,7 @@ const deal = {
id: 'GBP',
},
issuedDate: nowDate.valueOf(),
coverDateConfirmed: true,
requestedCoverStartDate: nowDate.valueOf(),
'coverEndDate-day': format(nowPlusOneMonth, 'dd'),
'coverEndDate-month': format(nowPlusOneMonth, 'MM'),
Expand Down Expand Up @@ -261,6 +265,7 @@ const deal = {
'conversionRateDate-year': format(yesterday, 'yyyy'),
disbursementAmount: '10',
issuedDate: nowDate.valueOf(),
coverDateConfirmed: true,
requestedCoverStartDate: nowDate.valueOf(),
'coverEndDate-day': format(nowPlusOneMonth, 'dd'),
'coverEndDate-month': format(nowPlusOneMonth, 'MM'),
Expand Down Expand Up @@ -298,6 +303,7 @@ const deal = {
type: CONSTANTS.FACILITIES.FACILITY_TYPE.LOAN,
facilityStage: 'Unconditional',
hasBeenIssued: true,
coverDateConfirmed: true,
requestedCoverStartDate: nowDate.valueOf(),
'coverEndDate-day': format(nowPlusOneMonth, 'dd'),
'coverEndDate-month': format(nowPlusOneMonth, 'MM'),
Expand Down
247 changes: 151 additions & 96 deletions portal-api/api-tests/v1/deals/deals-status-facilities.api-test.js

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions portal-api/src/v1/controllers/deal-status.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,37 @@ exports.update = async (req, res) => {

let updatedDeal = await updateStatus(dealId, currentStatus, newStatus, user);

// First submission of the deal to the checker
if (currentStatus === CONSTANTS.DEAL.DEAL_STATUS.DRAFT && newStatus === CONSTANTS.DEAL.DEAL_STATUS.READY_FOR_APPROVAL) {
await updateFacilityCoverStartDates(user, updatedDeal);
}

// Add a comment to the deal
if (req.body.comments) {
updatedDeal = await addComment(dealId, req.body.comments, user);
}

// Update the deal
if (newStatus !== CONSTANTS.DEAL.DEAL_STATUS.CHANGES_REQUIRED && newStatus !== CONSTANTS.DEAL.DEAL_STATUS.SUBMITTED_TO_UKEF) {
updatedDeal = await updateDeal(dealId, updatedDeal, user);
}

// Subsequent submission of the deal to the checker
if (newStatus === CONSTANTS.DEAL.DEAL_STATUS.READY_FOR_APPROVAL) {
const canUpdateIssuedFacilitiesCoverStartDates = true;
const newIssuedFacilityStatus = 'Ready for check';

updatedDeal = await updateIssuedFacilities(user, currentStatus, updatedDeal, canUpdateIssuedFacilitiesCoverStartDates, newIssuedFacilityStatus);
}

// Send back the deal to the maker
if (newStatus === CONSTANTS.DEAL.DEAL_STATUS.CHANGES_REQUIRED) {
const canUpdateIssuedFacilitiesCoverStartDates = false;
const newIssuedFacilityStatus = "Maker's input required";

updatedDeal = await updateIssuedFacilities(user, currentStatus, updatedDeal, canUpdateIssuedFacilitiesCoverStartDates, newIssuedFacilityStatus);
updatedDeal = await updateIssuedFacilities(user, currentStatus, updatedDeal, false, newIssuedFacilityStatus);
}

// Submit to UKEF / TFM
if (newStatus === CONSTANTS.DEAL.DEAL_STATUS.SUBMITTED_TO_UKEF) {
await updateSubmittedIssuedFacilities(user, updatedDeal);

Expand All @@ -129,10 +134,12 @@ exports.update = async (req, res) => {
await api.tfmDealSubmit(dealId, CONSTANTS.DEAL.DEAL_TYPE.BSS_EWCS, user);
}

// UKEF Approval
if (newStatus === CONSTANTS.DEAL.DEAL_STATUS.UKEF_APPROVED_WITHOUT_CONDITIONS || newStatus === CONSTANTS.DEAL.DEAL_STATUS.UKEF_APPROVED_WITH_CONDITIONS) {
updatedDeal = await createApprovalDate(dealId);
}

// Send status update emails
if (newStatus !== currentStatus) {
await sendStatusUpdateEmails(updatedDeal, currentStatus, user);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,56 @@
const CONSTANTS = require('../../../constants');
const { getNowAsEpoch } = require('../../helpers/date');
const facilitiesController = require('../facilities.controller');

/**
* Updates the cover start dates of facilities in a deal.
* @param {object} user - The user object representing the user performing the update.
* @param {object} deal - The deal object containing the facilities to be updated.
* @returns {object} - The modified deal object with updated facility cover start dates.
*/
const updateFacilityCoverStartDates = async (user, deal) => {
const modifiedDeal = deal;
try {
const modifiedDeal = { ...deal };

if (modifiedDeal.facilities.length) {
modifiedDeal.facilities.forEach(async (facilityId) => {
const facility = await facilitiesController.findOne(facilityId);
if (!modifiedDeal.facilities || !modifiedDeal.facilities?.length) {
console.error('No facilities found in deal %s', modifiedDeal._id);
throw new Error(`No facilities found in deal ${modifiedDeal._id}`);
}

for (const facilityId of modifiedDeal.facilities) {
const facility = await facilitiesController.findOne(facilityId);
const { facilityStage } = facility;
const canUpdate =
(facilityStage === CONSTANTS.FACILITIES.FACILITIES_STAGE.BOND.ISSUED || facilityStage === CONSTANTS.FACILITIES.FACILITIES_STAGE.LOAN.UNCONDITIONAL) &&
!facility.requestedCoverStartDate &&
!facility.coverDateConfirmed;

const shouldUpdate = ((facilityStage === CONSTANTS.FACILITIES.FACILITIES_STAGE.BOND.ISSUED
|| facilityStage === CONSTANTS.FACILITIES.FACILITIES_STAGE.LOAN.UNCONDITIONAL)
&& !facility.requestedCoverStartDate);
if (canUpdate) {
console.info('⚡ Updating facility %s cover start date', facilityId);

if (shouldUpdate) {
const now = Date.now();
const today = new Date();
const nowAsEpoch = getNowAsEpoch();

facility.updatedAt = now;
facility.requestedCoverStartDate = now;
facility.updatedAt = nowAsEpoch;
facility.coverDateConfirmed = true;
facility.requestedCoverStartDate = nowAsEpoch;
facility['requestedCoverStartDate-day'] = today.getDate();
facility['requestedCoverStartDate-month'] = today.getMonth() + 1;
facility['requestedCoverStartDate-year'] = today.getFullYear();

const { data } = await facilitiesController.update(
deal._id,
facilityId,
facility,
user,
);
return data;
const { data } = await facilitiesController.update(deal._id, facilityId, facility, user);

if (!data) {
console.error('Error updating facility cover start date for facility %s with response %o', facilityId, data);
}
}
return facility;
});
}
}

return deal;
return modifiedDeal;
} catch (error) {
console.error("An error occurred while updating %s deal's facilities cover start date %o", deal._id, error);
return deal;
}
};

module.exports = updateFacilityCoverStartDates;
Loading

0 comments on commit ef51d86

Please sign in to comment.