diff --git a/backend/src/components/application.js b/backend/src/components/application.js index c63750fa..9a3c6b85 100644 --- a/backend/src/components/application.js +++ b/backend/src/components/application.js @@ -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, 'ccof_ProgramYear@odata.bind': `/ccof_program_years(${application.programYearId})`, 'ccof_Organization@odata.bind': `/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, 'ccof_Facility@odata.bind': `/accounts(${facility.facilityID})`, 'ccof_Application@odata.bind': `/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, 'ccof_Application@odata.bind': `/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, { 'ccof_ccfri@odata.bind': `/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,11 +160,8 @@ 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. @@ -178,26 +169,19 @@ async function upsertParentFees(req, res) { //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, 'ccof_ChildcareCategory@odata.bind': childCareCategory, 'ccof_ProgramYear@odata.bind': programYear, + 'ccof_ApplicationCCFRI@odata.bind': `/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,7 +210,7 @@ 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, @@ -237,25 +218,17 @@ async function upsertParentFees(req, res) { 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,10 +247,10 @@ 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) { @@ -285,11 +258,9 @@ async function postClosureDates(dates, ccfriApplicationGuid, res) { 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, 'ccof_ApplicationCCFRI@odata.bind': `/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,7 +313,7 @@ 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); @@ -350,30 +321,30 @@ async function updateECEWEApplication(req, res) { } 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]['ccof_application@odata.bind'] = '/ccof_applications(' + req.params.applicationId + ')'; forBackFacilities[key]['ccof_Facility@odata.bind'] = '/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;