generated from bcgov/vue-scaffold
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #572 from bcgov/ccfri-app-broken
save fees CCFRI
- Loading branch information
Showing
1 changed file
with
33 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,17 +39,15 @@ const { getBrowserContext, closeBrowser } = require('../util/browser'); | |
const { ChangeRequestMappings, ChangeActionRequestMappings, NewFacilityMappings, MtfiMappings } = require('../util/mapping/ChangeRequestMappings'); | ||
|
||
async function renewCCOFApplication(req, res) { | ||
log.info('renew CCOF application called'); | ||
try { | ||
const application = req.body; | ||
let payload = { | ||
const payload = { | ||
ccof_providertype: application.providerType == 'GROUP' ? ORGANIZATION_PROVIDER_TYPES.GROUP : ORGANIZATION_PROVIDER_TYPES.FAMILY, | ||
ccof_applicationtype: CCOF_APPLICATION_TYPES.RENEW, | ||
'[email protected]': `/ccof_program_years(${application.programYearId})`, | ||
'[email protected]': `/ccof_program_years(${application.organizationId})`, | ||
}; | ||
log.info('Payload for renew is: ', payload.toJSON); | ||
let applicationGuid = await postOperation('ccof_applications', payload); | ||
const applicationGuid = await postOperation('ccof_applications', payload); | ||
//After the application is created, get the application guid | ||
return res.status(HttpStatus.CREATED).json({ applicationId: applicationGuid }); | ||
} catch (e) { | ||
|
@@ -74,7 +72,6 @@ async function patchCCFRIApplication(req, res) { | |
|
||
async function deleteCCFRIApplication(req, res) { | ||
try { | ||
log.info('deleteCCFRIApplication - ccfriId: ', req.params.ccfriId); | ||
await deleteOperationWithObjectId('ccof_applicationccfris', req.params.ccfriId); | ||
return res.status(HttpStatus.OK).json(); | ||
} catch (e) { | ||
|
@@ -85,12 +82,12 @@ async function deleteCCFRIApplication(req, res) { | |
|
||
//creates or updates CCFRI application. | ||
async function updateCCFRIApplication(req, res) { | ||
let body = req.body; | ||
let retVal = []; | ||
const body = req.body; | ||
const retVal = []; | ||
try { | ||
await Promise.all( | ||
body.map(async (facility) => { | ||
let payload = { | ||
const payload = { | ||
ccof_ccfrioptin: facility.optInResponse, | ||
'[email protected]': `/accounts(${facility.facilityID})`, | ||
'[email protected]': `/ccof_applications(${facility.applicationID})`, | ||
|
@@ -114,13 +111,11 @@ async function updateCCFRIApplication(req, res) { | |
//requirements changed so now we DO bind to main app... leaving this here for now just in case it changes again. | ||
// if (!facility.changeRequestNewFacilityId){ | ||
// payload = {...payload, '[email protected]': `/ccof_applications(${facility.applicationID})`}; | ||
// } | ||
log.info('patch ccfri payload', payload); | ||
// }; | ||
|
||
let response = undefined; | ||
if (facility.ccfriApplicationId) { | ||
response = await patchOperationWithObjectId('ccof_applicationccfris', facility.ccfriApplicationId, payload); | ||
log.info('CCFRI RESP!!!!!!!', response); | ||
retVal.push(response); | ||
} else { | ||
response = await postOperation('ccof_applicationccfris', payload); | ||
|
@@ -134,13 +129,12 @@ async function updateCCFRIApplication(req, res) { | |
|
||
//if this ccfri application is linked to a new facility change request, add the linkage to the New Facility Change Request | ||
if (facility.changeRequestNewFacilityId) { | ||
let resp = await updateChangeRequestNewFacility(facility.changeRequestNewFacilityId, { | ||
const resp = await updateChangeRequestNewFacility(facility.changeRequestNewFacilityId, { | ||
'[email protected]': `/ccof_applicationccfris(${facility.ccfriApplicationId ? facility.ccfriApplicationId : response})`, | ||
}); | ||
retVal.push(resp); | ||
} | ||
await sleep(100); //slow down the hits to dynamics. | ||
//log.info('res data:' , response); | ||
}), | ||
); //end for each | ||
} catch (e) { | ||
|
@@ -166,38 +160,28 @@ async function getApprovableFeeSchedules(req, res) { | |
/* child care and program year GUIDs are looked up in AddNewFees.vue */ | ||
|
||
async function upsertParentFees(req, res) { | ||
let body = req.body; | ||
|
||
log.info(body); | ||
const body = req.body; | ||
let hasError = false; | ||
let theResponse = []; | ||
|
||
//the front end sends over an array of objects. This loops through the array and sends a dynamics API request | ||
//for each object. | ||
body.forEach(async (feeGroup) => { | ||
//only call the delete API if there is a GUID acossciated to that child care category fee group | ||
if (feeGroup?.deleteMe && feeGroup?.parentFeeGUID) { | ||
try { | ||
let response = await deleteOperationWithObjectId('ccof_application_ccfri_childcarecategories', feeGroup.parentFeeGUID); | ||
log.info('delete feeGroup res:', response); | ||
theResponse.push(res.status(HttpStatus.OK).json(response)); | ||
await deleteOperationWithObjectId('ccof_application_ccfri_childcarecategories', feeGroup.parentFeeGUID); | ||
} catch (e) { | ||
//log.info(e); | ||
hasError = true; | ||
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(); | ||
//theResponse.push( res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data? e.data : e?.status )); | ||
} | ||
} else if (feeGroup?.feeFrequency) { | ||
let childCareCategory = `/ccof_childcare_categories(${feeGroup.childCareCategory})`; | ||
let programYear = `/ccof_program_years(${feeGroup.programYear})`; | ||
|
||
// log.info(feeGroup.notes); | ||
// log.info(feeGroup.ccfriApplicationGuid); | ||
|
||
let payload = { | ||
const childCareCategory = `/ccof_childcare_categories(${feeGroup.childCareCategory})`; | ||
const programYear = `/ccof_program_years(${feeGroup.programYear})`; | ||
const payload = { | ||
ccof_frequency: feeGroup.feeFrequency, | ||
'[email protected]': childCareCategory, | ||
'[email protected]': programYear, | ||
'[email protected]': `/ccof_applicationccfris(${feeGroup.ccfriApplicationGuid})`, | ||
}; | ||
|
||
Object.assign(payload, { | ||
|
@@ -214,13 +198,10 @@ async function upsertParentFees(req, res) { | |
ccof_feb: feeGroup.febFee, | ||
ccof_mar: feeGroup.marFee, | ||
}); | ||
let url = `_ccof_applicationccfri_value=${feeGroup.ccfriApplicationGuid},_ccof_childcarecategory_value=${feeGroup.childCareCategory},_ccof_programyear_value=${feeGroup.programYear} `; | ||
const url = `_ccof_applicationccfri_value=${feeGroup.ccfriApplicationGuid},_ccof_childcarecategory_value=${feeGroup.childCareCategory},_ccof_programyear_value=${feeGroup.programYear} `; | ||
try { | ||
let response = await patchOperationWithObjectId('ccof_application_ccfri_childcarecategories', url, payload); | ||
theResponse.push(res.status(HttpStatus.CREATED).json(response)); | ||
await patchOperationWithObjectId('ccof_application_ccfri_childcarecategories', url, payload); | ||
} catch (e) { | ||
//log.info(e); | ||
theResponse.push(res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status)); | ||
hasError = true; | ||
} | ||
} | ||
|
@@ -229,33 +210,25 @@ async function upsertParentFees(req, res) { | |
//if no notes, don't bother sending any requests. Even if left blank, front end will send over an empty string | ||
//so body[0].notes will always exist | ||
|
||
let payload = { | ||
const payload = { | ||
ccof_informationccfri: body[0].notes, | ||
ccof_formcomplete: body[0].ccof_formcomplete, | ||
ccof_has_rfi: body[0].ccof_has_rfi, | ||
ccof_feecorrectccfri: body[0].existingFeesCorrect, | ||
ccof_chargefeeccfri: body[0].hasClosureFees, | ||
}; | ||
|
||
log.info(body[0].hasClosureFees); | ||
try { | ||
let response = await patchOperationWithObjectId('ccof_applicationccfris', body[0].ccfriApplicationGuid, payload); | ||
log.info('notesRes', response); | ||
theResponse.push(res.status(HttpStatus.CREATED).json(response)); | ||
await patchOperationWithObjectId('ccof_applicationccfris', body[0].ccfriApplicationGuid, payload); | ||
} catch (e) { | ||
theResponse.push(res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status)); | ||
hasError = true; | ||
} | ||
|
||
//dates array will always exist - even if blank. | ||
//we should save the empty field to dynamics if user selects "no" on "Do you charge parent fees at this facility for any closures on business days" | ||
log.info(body[0].facilityClosureDates); | ||
try { | ||
let response = await postClosureDates(body[0].facilityClosureDates, body[0].ccfriApplicationGuid, res); | ||
//log.info('datesRes', response); | ||
theResponse.push(res.status(HttpStatus.CREATED).json(response)); | ||
await postClosureDates(body[0].facilityClosureDates, body[0].ccfriApplicationGuid, res); | ||
} catch (e) { | ||
theResponse.push(res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status)); | ||
hasError = true; | ||
} | ||
|
||
|
@@ -274,22 +247,20 @@ function formatTimeForBack(timeString) { | |
} | ||
|
||
async function postClosureDates(dates, ccfriApplicationGuid, res) { | ||
let retVal = []; | ||
const retVal = []; | ||
|
||
//delete all the old closure dates from the application - otherwise we will get duplicates when we save | ||
let dynamicsClosureDates = await getCCFRIClosureDates(ccfriApplicationGuid); | ||
const dynamicsClosureDates = await getCCFRIClosureDates(ccfriApplicationGuid); | ||
|
||
//don't bother trying to delete if there are no dates saved | ||
if (dynamicsClosureDates.length > 0) { | ||
try { | ||
await Promise.all( | ||
dynamicsClosureDates.map(async (date) => { | ||
await deleteOperationWithObjectId('ccof_application_ccfri_closures', date.closureDateId); | ||
//log.info(response); | ||
}), | ||
); | ||
} catch (e) { | ||
log.info('something broke when deleting existing closure dates.'); | ||
log.info(e); | ||
//return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data? e.data : e?.status ); | ||
} | ||
|
@@ -299,14 +270,14 @@ async function postClosureDates(dates, ccfriApplicationGuid, res) { | |
//if the user selects an end date, create a start and end date. else, use the only date for start and end. | ||
await Promise.all( | ||
dates.map(async (date) => { | ||
let payload = { | ||
const payload = { | ||
ccof_startdate: formatTimeForBack(date.formattedStartDate), | ||
ccof_paidclosure: date.feesPaidWhileClosed, | ||
ccof_enddate: date.formattedEndDate ? formatTimeForBack(date.formattedEndDate) : formatTimeForBack(date.formattedStartDate), | ||
ccof_comment: date.closureReason, | ||
'[email protected]': `/ccof_applicationccfris(${ccfriApplicationGuid})`, | ||
}; | ||
let response = await postOperation('ccof_application_ccfri_closures', payload); | ||
const response = await postOperation('ccof_application_ccfri_closures', payload); | ||
retVal.push(response); | ||
}), | ||
); | ||
|
@@ -319,13 +290,13 @@ async function postClosureDates(dates, ccfriApplicationGuid, res) { | |
|
||
async function getECEWEApplication(req, res) { | ||
try { | ||
let operation = | ||
const 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 = []; | ||
const forFrontFacilities = []; | ||
Object.values(eceweApp.data.facilities).forEach((value) => forFrontFacilities.push(new MappableObjectForFront(value, ECEWEFacilityMappings).data)); | ||
eceweApp.data.facilities = forFrontFacilities; | ||
return res.status(HttpStatus.OK).json(eceweApp); | ||
|
@@ -342,38 +313,38 @@ async function updateECEWEApplication(req, res) { | |
application.ccof_ecewe_employeeunion = application.ccof_ecewe_optin == 0 ? null : application.ccof_ecewe_employeeunion; | ||
try { | ||
log.verbose('updateECEWEApplication: payload', application); | ||
let response = await patchOperationWithObjectId('ccof_applications', req.params.applicationId, application); | ||
const response = await patchOperationWithObjectId('ccof_applications', req.params.applicationId, application); | ||
return res.status(HttpStatus.OK).json(response); | ||
} catch (e) { | ||
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status); | ||
} | ||
} | ||
|
||
async function updateECEWEFacilityApplication(req, res) { | ||
let facilities = req.body; | ||
let forBackFacilities = []; | ||
const facilities = req.body; | ||
const forBackFacilities = []; | ||
let response; | ||
Object.values(facilities).forEach((value) => forBackFacilities.push(new MappableObjectForBack(value, ECEWEFacilityMappings).data)); | ||
let eceweApplicationId; | ||
try { | ||
for (let key in forBackFacilities) { | ||
for (const key in forBackFacilities) { | ||
// add join attributes for application and facility | ||
forBackFacilities[key]['[email protected]'] = '/ccof_applications(' + req.params.applicationId + ')'; | ||
forBackFacilities[key]['[email protected]'] = '/accounts(' + forBackFacilities[key]._ccof_facility_value + ')'; | ||
eceweApplicationId = forBackFacilities[key].ccof_applicationeceweid; | ||
let changeRequestNewFacilityId = forBackFacilities[key].ccof_change_request_new_facilityid; | ||
const changeRequestNewFacilityId = forBackFacilities[key].ccof_change_request_new_facilityid; | ||
// remove attributes that are already used in payload join (above) and not needed. | ||
delete forBackFacilities[key].ccof_applicationeceweid; | ||
delete forBackFacilities[key]._ccof_facility_value; | ||
delete forBackFacilities[key].ccof_change_request_new_facilityid; | ||
|
||
let facility = forBackFacilities[key]; | ||
const facility = forBackFacilities[key]; | ||
if (eceweApplicationId) { | ||
// send PATCH (update existing ECEWE facility) | ||
response = await patchOperationWithObjectId('ccof_applicationecewes', eceweApplicationId, facility); | ||
} else { | ||
// send POST (create a new ECEWE facility) | ||
let operation = 'ccof_applicationecewes'; | ||
const operation = 'ccof_applicationecewes'; | ||
response = await postOperation(operation, facility); | ||
facilities[key].eceweApplicationId = response; | ||
//if this is a new facility change request, link ECEWE application to the New Facility Change Request | ||
|
@@ -391,7 +362,7 @@ async function updateECEWEFacilityApplication(req, res) { | |
/* Get the user declaration for a given application id. */ | ||
async function getDeclaration(req, res) { | ||
try { | ||
let operation = 'ccof_applications(' + req.params.applicationId + ')?$select=ccof_consent,ccof_submittedby,ccof_declarationastatus,ccof_declarationbstatus,statuscode'; | ||
const operation = 'ccof_applications(' + req.params.applicationId + ')?$select=ccof_consent,ccof_submittedby,ccof_declarationastatus,ccof_declarationbstatus,statuscode'; | ||
let declaration = await getOperation(operation); | ||
declaration = new MappableObjectForFront(declaration, DeclarationMappings); | ||
return res.status(HttpStatus.OK).json(declaration); | ||
|
@@ -405,7 +376,7 @@ async function getDeclaration(req, res) { | |
async function submitApplication(req, res) { | ||
let declaration = new MappableObjectForBack(req.body, DeclarationMappings); | ||
declaration.data.statuscode = APPLICATION_STATUS_CODES.SUBMITTED; | ||
let ccfriFacilitiesToLock = JSON.parse(JSON.stringify(declaration)); | ||
const ccfriFacilitiesToLock = JSON.parse(JSON.stringify(declaration)); | ||
declaration = declaration.toJSON(); | ||
try { | ||
delete declaration.facilities; | ||
|