Skip to content

Commit

Permalink
Merge pull request #500 from bcgov/release-196
Browse files Browse the repository at this point in the history
Release 196
  • Loading branch information
jenbeckett authored Jan 19, 2024
2 parents 5c0b94a + f273c61 commit eb9a8ef
Show file tree
Hide file tree
Showing 67 changed files with 3,077 additions and 1,372 deletions.
60 changes: 53 additions & 7 deletions backend/src/components/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ async function postClosureDates(dates, ccfriApplicationGuid, res) {

async function getECEWEApplication(req, res) {
try {
let operation = 'ccof_applications(' + req.params.applicationId + ')?$select=ccof_ecewe_optin,ccof_ecewe_employeeunion,ccof_ecewe_selecttheapplicablefundingmodel,ccof_ecewe_selecttheapplicablesector,ccof_ecewe_confirmation&$expand=ccof_ccof_application_ccof_applicationecewe_application($select=ccof_name,_ccof_facility_value,ccof_optintoecewe,statuscode)';
let operation = 'ccof_applications(' + req.params.applicationId + ')?$select=ccof_ecewe_optin,ccof_ecewe_employeeunion,ccof_ecewe_selecttheapplicablefundingmodel,ccof_ecewe_selecttheapplicablesector,ccof_public_sector_employer,ccof_ecewe_confirmation&$expand=ccof_ccof_application_ccof_applicationecewe_application($select=ccof_name,_ccof_facility_value,ccof_optintoecewe,statuscode)';
let eceweApp = await getOperation(operation);
eceweApp = new MappableObjectForFront(eceweApp, ECEWEApplicationMappings);
let forFrontFacilities = [];
Expand Down Expand Up @@ -705,16 +705,37 @@ async function getMTFIChangeData(changeActionId) {
});
return mtfi;
}
//and Microsoft.Dynamics.CRM.In(PropertyName='_ccof_application_value',PropertyValues=[${applicationId}]));
async function getChangeRequestsFromApplicationId(applicationIds){

let str = '[';

const regex = new RegExp('([^,]+)' , 'g');
const found = applicationIds.match(regex);
found.forEach((app, index) => {
str = str + `'${app}'`;
if (index != found.length -1 ){
str = str + ',';
}
else{
str = str + ']';
}
});

log.info(str);

async function getChangeRequestsFromApplicationId(applicationId){
try {
let operation = `ccof_change_requests?$expand=ccof_change_action_change_request&$select=${getMappingString(ChangeRequestMappings)}&$filter=_ccof_application_value eq ${applicationId}`;
let operation = `ccof_change_requests?$expand=ccof_change_action_change_request&$select=${getMappingString(ChangeRequestMappings)}&$filter=(Microsoft.Dynamics.CRM.In(PropertyName='ccof_application',PropertyValues=${str}))`;
//let operation = `ccof_change_requests?$expand=ccof_change_action_change_request&$select=${getMappingString(ChangeRequestMappings)}&$filter=_ccof_application_value eq ${applicationId}`;
let changeRequests = await getOperation(operation);
changeRequests = changeRequests.value;

// log.info('ALL CHANGE REQZ');
// log.info(changeRequests);

let payload = [];

log.verbose(changeRequests);
//log.verbose(changeRequests);
await Promise.all(changeRequests.map(async (request) => {

let req = new MappableObjectForFront(request, ChangeRequestMappings).toJSON();
Expand All @@ -735,11 +756,11 @@ async function getChangeRequestsFromApplicationId(applicationId){
payload.push(req);
}));

log.info('final payload', payload);
//log.info('final payload', payload);
return payload;
} catch (e) {
log.error('An error occurred while getting change request', e);
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status);
throw e;
}

}
Expand All @@ -758,6 +779,30 @@ async function getChangeRequest(req, res){

}

async function deletePcfApplication(req, res){
try {
let operation = `ccof_applications(${req.params.applicationId})?$expand=ccof_application_basefunding_Application($select=_ccof_facility_value)`;
let application = await getOperation(operation);

//loop thru to grab facility ID's and delete all of them
await Promise.all(application['ccof_application_basefunding_Application'].map(async (facility) => {
await deleteOperationWithObjectId('accounts', facility['_ccof_facility_value']);
//log.info(response);
}));

//delete the application
await deleteOperationWithObjectId('ccof_applications', req.params.applicationId);

//and delete the org. We must delete the org otherwise the user will be linked to multiple orgs in dynamics
await deleteOperationWithObjectId('accounts', application['_ccof_organization_value']);

return res.status(HttpStatus.OK).json();
} catch (e) {
log.error('An error occurred while deleting PCF', e);
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status);
}
}

module.exports = {
updateCCFRIApplication,
upsertParentFees,
Expand All @@ -772,5 +817,6 @@ module.exports = {
getChangeRequest,
patchCCFRIApplication,
deleteCCFRIApplication,
printPdf
printPdf,
deletePcfApplication
};
51 changes: 41 additions & 10 deletions backend/src/components/changeRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
const log = require('./logger');
const { MappableObjectForFront, MappableObjectForBack, getMappingString } = require('../util/mapping/MappableObject');
const { ChangeRequestMappings, ChangeActionRequestMappings, MtfiMappings, NewFacilityMappings } = require('../util/mapping/ChangeRequestMappings');
const { UserProfileBaseCCFRIMappings } = require('../util/mapping/Mappings');
const { UserProfileBaseCCFRIMappings, UserProfileBaseFundingMappings, UserProfileECEWEMappings, UserProfileApplicationMappings} = require('../util/mapping/Mappings');
const { ChangeRequestUnlockMapping } = require('../util/mapping/ChangeRequestMappings');

const { mapFacilityObjectForBack } = require('./facility');
const { printPdf } = require('./application');
Expand Down Expand Up @@ -32,6 +33,34 @@ function mapChangeRequestForBack(data, changeType) {
return changeRequestForBack;
}

async function getChangeActionNewFacilitityDetails(changeActionId) {
if (changeActionId) {
try {
let operation = `ccof_change_request_new_facilities?$filter=_ccof_change_action_value eq '${changeActionId}'&$expand=ccof_ccfri($select=${getMappingString(UserProfileBaseCCFRIMappings)}),ccof_ecewe($select=${getMappingString(UserProfileECEWEMappings)}),ccof_CCOF($select=${getMappingString(UserProfileBaseFundingMappings)})`;
let changeActionDetails = await getOperation(operation);
let details = changeActionDetails?.value;

log.info('!!!!!!!!!!');
log.info(details);
let retVal = [];
details?.forEach(el => {
let data = new MappableObjectForFront(el, NewFacilityMappings).toJSON();
data.ccfri = new MappableObjectForFront(el.ccof_ccfri, UserProfileBaseCCFRIMappings).toJSON();
data.ecewe = new MappableObjectForFront(el.ccof_ecewe, UserProfileECEWEMappings).toJSON();
log.info(data.ecewe);
data.baseFunding = new MappableObjectForFront(el.ccof_CCOF, UserProfileBaseFundingMappings).toJSON();
retVal.push(data);
});
return retVal;
} catch (e) {
log.error('Unable to get change action details',e);
}
} else {
return undefined;
}
}


// get Change Action details. depending on the entity, we may want to get details 2 level below change action
async function getChangeActionDetails(changeActionId, changeDetailEntity, changeDetailMapper, joiningTable, joiningTableMapping) {
if (changeActionId && changeDetailEntity && changeDetailMapper) {
Expand Down Expand Up @@ -65,6 +94,7 @@ async function getChangeActionDetails(changeActionId, changeDetailEntity, change

async function mapChangeRequestObjectForFront(data) {
let retVal = new MappableObjectForFront(data, ChangeRequestMappings).toJSON();

let changeList = [];
await Promise.all( retVal.changeActions?.map(async (el) => {
let changeAction = new MappableObjectForFront(el, ChangeActionRequestMappings).toJSON();
Expand All @@ -74,10 +104,13 @@ async function mapChangeRequestObjectForFront(data) {
item.ccfriStatus = getLabelFromValue(item.ccfriStatus, CCFRI_STATUS_CODES, 'NOT STARTED');
});
changeAction.mtfi = mtfi;
} else if (changeAction.changeType == CHANGE_REQUEST_TYPES.NEW_FACILITY) {
const newFacilities = await getChangeActionDetails(changeAction.changeActionId, 'ccof_change_request_new_facilities', NewFacilityMappings);
}
else if (changeAction.changeType == CHANGE_REQUEST_TYPES.NEW_FACILITY) {
const newFacilities = await getChangeActionNewFacilitityDetails(changeAction.changeActionId);
changeAction.newFacilities = newFacilities;
}
let unlockVals = new MappableObjectForFront(el, ChangeRequestUnlockMapping).toJSON();
changeAction = {...changeAction, ...unlockVals};
changeList.push(changeAction);
}));
retVal.changeActions = changeList;
Expand All @@ -89,16 +122,12 @@ async function mapChangeRequestObjectForFront(data) {

// get Change Request
async function getChangeRequest(req, res) {
log.info('get changeRequest called');

try {
let operation = `ccof_change_requests(${req.params.changeRequestId})?$expand=ccof_change_action_change_request($select=ccof_change_actionid,statuscode,ccof_changetype,createdon)`;
let operation = `ccof_change_requests(${req.params.changeRequestId})?$expand=ccof_change_action_change_request($select=ccof_change_actionid,statuscode,ccof_changetype,createdon,ccof_unlock_ecewe,ccof_unlock_ccof,ccof_unlock_supporting_document,ccof_unlock_other_changes_document,ccof_unlock_change_request,ccof_unlock_licence_upload)`;
let changeRequest = await getOperation(operation);
changeRequest = await mapChangeRequestObjectForFront(changeRequest);
changeRequest.providerType = getLabelFromValue(changeRequest.providerType , ORGANIZATION_PROVIDER_TYPES);
changeRequest.externalStatus = getLabelFromValue(changeRequest.externalStatus , CHANGE_REQUEST_EXTERNAL_STATUS_CODES);
log.info(changeRequest);
log.info(CHANGE_REQUEST_EXTERNAL_STATUS_CODES);
return res.status(HttpStatus.OK).json(changeRequest);
} catch (e) {
console.log('e', e);
Expand Down Expand Up @@ -146,7 +175,7 @@ async function createChangeRequest(req, res) {
else if(changeType === 'PDF_CHANGE'){
changeType = CHANGE_REQUEST_TYPES.PDF_CHANGE;
}
log.info('change type', changeType);
//log.info('change type', changeType);
changeRequest = mapChangeRequestForBack(changeRequest, changeType);
const changeRequestId = await postOperation('ccof_change_requests', changeRequest);
let operation = `ccof_change_requests(${changeRequestId})?$select=ccof_change_requestid&$expand=ccof_change_action_change_request($select=ccof_change_actionid,statuscode)`;
Expand Down Expand Up @@ -313,8 +342,10 @@ async function getChangeRequestMTFIByCcfriId(req, res){
let operation = `ccof_applicationccfris(${req.params.ccfriId})?$expand=ccof_change_request_mtfi_application_ccfri`;
let response = await getOperation(operation);
let mtfiDetails = [];
let rfiDetails = new MappableObjectForFront(response, UserProfileBaseCCFRIMappings).toJSON();
//Add in the rfi details mapping so on the front when we update hasRFI for the first time, we have the value needed to update it
response?.ccof_change_request_mtfi_application_ccfri?.forEach(mtfiFacility => {
mtfiDetails.push(new MappableObjectForFront(mtfiFacility, MtfiMappings).toJSON());
mtfiDetails.push({...new MappableObjectForFront(mtfiFacility, MtfiMappings).toJSON(), ...rfiDetails});
});
return res.status(HttpStatus.OK).json(mtfiDetails);
}
Expand Down
29 changes: 22 additions & 7 deletions backend/src/components/facility.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ function mapFacilityObjectForBack(data) {
if (facilityForBack.ccof_facilitystartdate) {
facilityForBack.ccof_facilitystartdate = `${facilityForBack.ccof_facilitystartdate}-01-01`;
}

if (facilityForBack.ccof_licensestartdate) {
facilityForBack.ccof_licensestartdate = facilityForBack.ccof_licensestartdate + 'T12:00:00-07:00';
}
if (data.hasReceivedFunding === 'no') {
facilityForBack.ccof_everreceivedfundingundertheccofprogram = 100000000;
} else if (data.hasReceivedFunding === 'yes') {
facilityForBack.ccof_everreceivedfundingundertheccofprogram = 100000001;
} else if (data.hasReceivedFunding === 'yes') {
facilityForBack.ccof_everreceivedfundingundertheccofprogram = 100000000;
} else if (data.hasReceivedFunding === 'yesFacility') {
facilityForBack.ccof_everreceivedfundingundertheccofprogram = 100000002;
} else if (data.hasReceivedFunding) {
Expand All @@ -60,9 +62,9 @@ function mapFacilityObjectForFront(data) {
let obj = new MappableObjectForFront(data, FacilityMappings).toJSON();

//TODO: map this if it is returned from dynamics
if (data.ccof_everreceivedfundingundertheccofprogram === 100000000) {
if (data.ccof_everreceivedfundingundertheccofprogram === 100000001) {
obj.hasReceivedFunding = 'no';
} else if (data.ccof_everreceivedfundingundertheccofprogram === 100000001) {
} else if (data.ccof_everreceivedfundingundertheccofprogram === 100000000) {
obj.hasReceivedFunding = 'yes';
} else if (data.ccof_everreceivedfundingundertheccofprogram === 100000002) {
obj.hasReceivedFunding = 'yesFacility';
Expand Down Expand Up @@ -169,6 +171,17 @@ async function getFacilityChildCareTypes(req, res){
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data? e.data : e?.status );
}
}
//a wrapper fn as getCCFRIClosureDates does not take in a req/res
async function returnCCFRIClosureDates(req, res){
try {
const dateData = {dates: await getCCFRIClosureDates(req.params.ccfriId)};
return res.status(HttpStatus.OK).json(dateData);

} catch (e) {
log.error('failed with error', e);
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data? e.data : e?.status );
}
}

async function getCCFRIClosureDates(ccfriId){
const url = `ccof_applicationccfris(${ccfriId})?$select=ccof_name,&$expand=ccof_ccfri_closure_application_ccfri`;
Expand Down Expand Up @@ -379,9 +392,10 @@ async function getApprovedParentFees(req, res) {
}
);
}); //end for each

const retVal = {
facilityId: facilityId,
childCareTypes: childCareTypes
childCareTypes: childCareTypes,
};
return res.status(200).json(retVal);
} catch (e) {
Expand All @@ -402,6 +416,7 @@ module.exports = {
updateFacilityLicenseType,
getCCFRIClosureDates,
mapFacilityObjectForBack,
getApprovedParentFees
getApprovedParentFees,
returnCCFRIClosureDates
};

8 changes: 3 additions & 5 deletions backend/src/components/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ function sortByPropertyDesc(property){

async function getAllMessages(req, res) {
try {
let operation = 'emails?$select=activityid,createdon,description,lastopenedtime ,_regardingobjectid_value,subject&$expand=regardingobjectid_account_email($select=accountid,accountnumber,name)&$filter=(regardingobjectid_account_email/accountid eq ' + req.params.organizationId + ' and statecode eq 1)';
let operation = 'emails?$select=activityid,createdon,description,lastopenedtime,ccof_program_year,_regardingobjectid_value,subject&$expand=regardingobjectid_account_email($select=accountid,accountnumber,name)&$filter=(regardingobjectid_account_email/accountid eq ' + req.params.organizationId + ' and statecode eq 1)';
log.info('operation: ', operation);
let operationResponse = await getOperation(operation);
operationResponse.value.sort(sortByPropertyDesc('createdon'));
let allMessages = [];
operationResponse.value.forEach(item => {
let message = mapMessageObjectForFront(item);
if (message.lastOpenedTime)
message['isRead'] = true;
else
message['isRead'] = false;
message.isRead = message.lastOpenedTime ? true : false;
message.programYearValue = message.programYearValue?.replace(/[^\d/]/g, '');
allMessages.push(message);
});
return res.status(HttpStatus.OK).json(allMessages);
Expand Down
26 changes: 23 additions & 3 deletions backend/src/components/rfiApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ function formatDate(data, columnName) {
return data;
}

async function deleteRfiApplication(req, res){
let query = `ccof_rfipfis?$filter=(_ccof_applicationccfri_value eq ${req.params.ccfriId} and statuscode eq 1)`;

try {
const response = await getOperation(query);

//there should only every be one RFI application per ccfri app.
//if array empty - don't try to delete anything.
if (response?.value?.length > 0) {
log.info(response.value[0]);
await deleteOperationWithObjectId('ccof_rfipfis', response.value[0].ccof_rfipfiid);
}

return res.status(HttpStatus.OK).json({});
} catch (e) {
log.error(e);
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data? e.data : e?.status );
}
}

async function getRFIApplication(req, res) {
let query = `ccof_rfipfis?$filter=(_ccof_applicationccfri_value eq ${req.params.ccfriId} and statuscode eq 1)&$expand=ccof_ccof_rfipfi_ccof_rfi_pfi_fee_history_deta($select=ccof_feeafterincrease),ccof_ccof_rfipfi_ccof_rfipfiserviceexpansiondetail_rfipfi,ccof_rfi_pfi_other_funding_RFI_PFI, ccof_rfi_pfi_dcs_wi_detail_RFI_PFI_Detail,ccof_ccof_rfipfi_ccof_rfipfiexpenseinfo_rfipfi,ccof_rfipfi_ccof_rfipfi_IndegenousService`;
Expand All @@ -71,7 +90,7 @@ async function getRFIApplication(req, res) {
rfiApplication.data['expenseList'] = response.value[0].ccof_ccof_rfipfi_ccof_rfipfiexpenseinfo_rfipfi?.map(el=> formatDate(new MappableObjectForFront(el,ExpenseInformationMappings).data, 'date'));
rfiApplication.data['fundingList'] = response.value[0].ccof_rfi_pfi_other_funding_RFI_PFI?.map(el=> formatDate(new MappableObjectForFront(el,OtherFundingProgramMappings).data, 'date'));
rfiApplication.data['indigenousExpenseList'] = response.value[0].ccof_rfipfi_ccof_rfipfi_IndegenousService?.map(el=> formatDate(new MappableObjectForFront(el,IndigenousExpenseMappings).data, 'date'));

return res.status(HttpStatus.OK).json(rfiApplication);
} else {
return res.status(HttpStatus.OK).json({});
Expand Down Expand Up @@ -158,7 +177,7 @@ async function updateRFIApplication(req, res) {
payload['ccof_rfipfi@odata.bind'] = `/ccof_rfipfis(${rfipfiid})`;
await postOperation('ccof_rfipfiexpenseinfos', payload);
await sleep(100);
});
});
}

//rfipfiid, entityName, selectorName, filterName) {
Expand All @@ -172,7 +191,7 @@ async function updateRFIApplication(req, res) {
payload['ccof_rfipfi_IndegenousServiceExpansion@odata.bind'] = `/ccof_rfipfis(${rfipfiid})`;
await postOperation('ccof_rfipfiserviceexpansionindigenouscommunities', payload);
await sleep(100);
});
});
}

return res.status(HttpStatus.OK).json(friApplicationResponse);
Expand Down Expand Up @@ -218,4 +237,5 @@ module.exports = {
createRFIApplication,
updateRFIApplication,
getRFIMedian,
deleteRfiApplication
};
Loading

0 comments on commit eb9a8ef

Please sign in to comment.