diff --git a/backend/src/components/fundingAgreements.js b/backend/src/components/fundingAgreements.js index bbffc470..ee3db4a8 100644 --- a/backend/src/components/fundingAgreements.js +++ b/backend/src/components/fundingAgreements.js @@ -2,7 +2,7 @@ const { getOperation, patchOperationWithObjectId, getOperationWithObjectId, handleError } = require('./utils') const { MappableObjectForFront, MappableObjectForBack } = require('../util/mapping/MappableObject') const { buildDateFilterQuery, buildFilterQuery } = require('../util/common') -const { FundingAgreementMappings } = require('../util/mapping/Mappings') +const { FundingAgreementMappings, FundingReallocationRequestMappings } = require('../util/mapping/Mappings') const HttpStatus = require('http-status-codes') const log = require('./logger') const { isEmpty } = require('lodash') @@ -86,10 +86,24 @@ async function updateFundingAgreement(req, res) { } } +async function getFundingReallocationRequests(req, res) { + try { + const fundingReallocationRequests = [] + const operation = `ofm_funding_envelope_changes?$select=ofm_funding_envelope_changeid,_ofm_funding_value,ofm_funding_envelope_from,ofm_funding_envelope_to,ofm_amount_base,createdon,statuscode + &$filter=(_ofm_funding_value eq ${req?.params?.fundingAgreementId})&pageSize=500` + const response = await getOperation(operation) + response?.value?.forEach((reallocationRequest) => fundingReallocationRequests.push(new MappableObjectForFront(reallocationRequest, FundingReallocationRequestMappings).toJSON())) + return res.status(HttpStatus.OK).json(fundingReallocationRequests) + } catch (e) { + handleError(res, e) + } +} + module.exports = { getFundingAgreements, - updateFundingAgreement, getFundingAgreementById, - getRawFundingAgreementById, + getFundingReallocationRequests, getFundingPDFById, + getRawFundingAgreementById, + updateFundingAgreement, } diff --git a/backend/src/routes/fundingAgreements.js b/backend/src/routes/fundingAgreements.js index 37e786fe..e1343ffc 100644 --- a/backend/src/routes/fundingAgreements.js +++ b/backend/src/routes/fundingAgreements.js @@ -3,7 +3,7 @@ const passport = require('passport') const router = express.Router() const auth = require('../components/auth') const isValidBackendToken = auth.isValidBackendToken() -const { getFundingAgreements, updateFundingAgreement, getFundingAgreementById, getFundingPDFById } = require('../components/fundingAgreements') +const { getFundingAgreements, updateFundingAgreement, getFundingAgreementById, getFundingPDFById, getFundingReallocationRequests } = require('../components/fundingAgreements') const { param, query, validationResult, oneOf } = require('express-validator') const validateExpenseAuthority = require('../middlewares/validateExpenseAuthority.js') const validateFacility = require('../middlewares/validateFacility.js') @@ -76,3 +76,19 @@ router.patch( return updateFundingAgreement(req, res) }, ) + +/** + * Get the list of Funding Reallocation Requests + */ +router.get( + '/:fundingAgreementId/funding-reallocation-requests', + passport.authenticate('jwt', { session: false }), + isValidBackendToken, + // TODO (vietle-cgi) - update permission once we receive confirmation for this requirement + validatePermission(PERMISSIONS.VIEW_FUNDING_AGREEMENT), + [param('fundingAgreementId', 'URL param: [fundingAgreementId] is required').notEmpty().isUUID()], + (req, res) => { + validationResult(req).throw() + return getFundingReallocationRequests(req, res) + }, +) diff --git a/backend/src/util/mapping/Mappings.js b/backend/src/util/mapping/Mappings.js index fec6e279..95b130c4 100644 --- a/backend/src/util/mapping/Mappings.js +++ b/backend/src/util/mapping/Mappings.js @@ -346,6 +346,19 @@ const FundingAgreementMappings = [ { back: 'ofm_envelope_facility', front: 'envelopeFacility' }, ] +const FundingReallocationRequestMappings = [ + { back: 'ofm_funding_envelope_changeid', front: 'fundingEnvelopeId' }, + { back: '_ofm_funding_value', front: 'fundingId' }, + { back: 'ofm_funding_envelope_from', front: 'envelopeCodeFrom' }, + { back: 'ofm_funding_envelope_from@OData.Community.Display.V1.FormattedValue', front: 'envelopeNameFrom' }, + { back: 'ofm_funding_envelope_to', front: 'envelopeCodeTo' }, + { back: 'ofm_funding_envelope_to@OData.Community.Display.V1.FormattedValue', front: 'envelopeNameTo' }, + { back: 'ofm_amount_base', front: 'amount' }, + { back: 'createdon', front: 'date' }, + { back: 'statuscode', front: 'statusCode' }, + { back: 'statuscode@OData.Community.Display.V1.FormattedValue', front: 'statusName' }, +] + const PaymentMappings = [ { back: 'ofm_paymentid', front: 'paymentId' }, { back: 'ofm_name', front: 'paymentNumber' }, @@ -493,6 +506,7 @@ module.exports = { FacilityIntakeMappings, FacilityMappings, FundingAgreementMappings, + FundingReallocationRequestMappings, LicenceMappings, LicenceDetailsMappings, NotificationMappings, diff --git a/frontend/src/components/funding/BaseFundingCard.vue b/frontend/src/components/funding/BaseFundingCard.vue index ee5e0a91..41310d74 100644 --- a/frontend/src/components/funding/BaseFundingCard.vue +++ b/frontend/src/components/funding/BaseFundingCard.vue @@ -1,6 +1,6 @@