Skip to content

Commit 20e0905

Browse files
authored
Merge pull request #572 from bcgov/ccfri-app-broken
save fees CCFRI
2 parents 710fb49 + 1149fb6 commit 20e0905

File tree

1 file changed

+33
-62
lines changed

1 file changed

+33
-62
lines changed

backend/src/components/application.js

Lines changed: 33 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,15 @@ const { getBrowserContext, closeBrowser } = require('../util/browser');
3939
const { ChangeRequestMappings, ChangeActionRequestMappings, NewFacilityMappings, MtfiMappings } = require('../util/mapping/ChangeRequestMappings');
4040

4141
async function renewCCOFApplication(req, res) {
42-
log.info('renew CCOF application called');
4342
try {
4443
const application = req.body;
45-
let payload = {
44+
const payload = {
4645
ccof_providertype: application.providerType == 'GROUP' ? ORGANIZATION_PROVIDER_TYPES.GROUP : ORGANIZATION_PROVIDER_TYPES.FAMILY,
4746
ccof_applicationtype: CCOF_APPLICATION_TYPES.RENEW,
4847
'ccof_ProgramYear@odata.bind': `/ccof_program_years(${application.programYearId})`,
4948
'ccof_Organization@odata.bind': `/ccof_program_years(${application.organizationId})`,
5049
};
51-
log.info('Payload for renew is: ', payload.toJSON);
52-
let applicationGuid = await postOperation('ccof_applications', payload);
50+
const applicationGuid = await postOperation('ccof_applications', payload);
5351
//After the application is created, get the application guid
5452
return res.status(HttpStatus.CREATED).json({ applicationId: applicationGuid });
5553
} catch (e) {
@@ -74,7 +72,6 @@ async function patchCCFRIApplication(req, res) {
7472

7573
async function deleteCCFRIApplication(req, res) {
7674
try {
77-
log.info('deleteCCFRIApplication - ccfriId: ', req.params.ccfriId);
7875
await deleteOperationWithObjectId('ccof_applicationccfris', req.params.ccfriId);
7976
return res.status(HttpStatus.OK).json();
8077
} catch (e) {
@@ -85,12 +82,12 @@ async function deleteCCFRIApplication(req, res) {
8582

8683
//creates or updates CCFRI application.
8784
async function updateCCFRIApplication(req, res) {
88-
let body = req.body;
89-
let retVal = [];
85+
const body = req.body;
86+
const retVal = [];
9087
try {
9188
await Promise.all(
9289
body.map(async (facility) => {
93-
let payload = {
90+
const payload = {
9491
ccof_ccfrioptin: facility.optInResponse,
9592
'ccof_Facility@odata.bind': `/accounts(${facility.facilityID})`,
9693
'ccof_Application@odata.bind': `/ccof_applications(${facility.applicationID})`,
@@ -114,13 +111,11 @@ async function updateCCFRIApplication(req, res) {
114111
//requirements changed so now we DO bind to main app... leaving this here for now just in case it changes again.
115112
// if (!facility.changeRequestNewFacilityId){
116113
// payload = {...payload, 'ccof_Application@odata.bind': `/ccof_applications(${facility.applicationID})`};
117-
// }
118-
log.info('patch ccfri payload', payload);
114+
// };
119115

120116
let response = undefined;
121117
if (facility.ccfriApplicationId) {
122118
response = await patchOperationWithObjectId('ccof_applicationccfris', facility.ccfriApplicationId, payload);
123-
log.info('CCFRI RESP!!!!!!!', response);
124119
retVal.push(response);
125120
} else {
126121
response = await postOperation('ccof_applicationccfris', payload);
@@ -134,13 +129,12 @@ async function updateCCFRIApplication(req, res) {
134129

135130
//if this ccfri application is linked to a new facility change request, add the linkage to the New Facility Change Request
136131
if (facility.changeRequestNewFacilityId) {
137-
let resp = await updateChangeRequestNewFacility(facility.changeRequestNewFacilityId, {
132+
const resp = await updateChangeRequestNewFacility(facility.changeRequestNewFacilityId, {
138133
'ccof_ccfri@odata.bind': `/ccof_applicationccfris(${facility.ccfriApplicationId ? facility.ccfriApplicationId : response})`,
139134
});
140135
retVal.push(resp);
141136
}
142137
await sleep(100); //slow down the hits to dynamics.
143-
//log.info('res data:' , response);
144138
}),
145139
); //end for each
146140
} catch (e) {
@@ -166,38 +160,28 @@ async function getApprovableFeeSchedules(req, res) {
166160
/* child care and program year GUIDs are looked up in AddNewFees.vue */
167161

168162
async function upsertParentFees(req, res) {
169-
let body = req.body;
170-
171-
log.info(body);
163+
const body = req.body;
172164
let hasError = false;
173-
let theResponse = [];
174165

175166
//the front end sends over an array of objects. This loops through the array and sends a dynamics API request
176167
//for each object.
177168
body.forEach(async (feeGroup) => {
178169
//only call the delete API if there is a GUID acossciated to that child care category fee group
179170
if (feeGroup?.deleteMe && feeGroup?.parentFeeGUID) {
180171
try {
181-
let response = await deleteOperationWithObjectId('ccof_application_ccfri_childcarecategories', feeGroup.parentFeeGUID);
182-
log.info('delete feeGroup res:', response);
183-
theResponse.push(res.status(HttpStatus.OK).json(response));
172+
await deleteOperationWithObjectId('ccof_application_ccfri_childcarecategories', feeGroup.parentFeeGUID);
184173
} catch (e) {
185-
//log.info(e);
186174
hasError = true;
187175
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json();
188-
//theResponse.push( res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data? e.data : e?.status ));
189176
}
190177
} else if (feeGroup?.feeFrequency) {
191-
let childCareCategory = `/ccof_childcare_categories(${feeGroup.childCareCategory})`;
192-
let programYear = `/ccof_program_years(${feeGroup.programYear})`;
193-
194-
// log.info(feeGroup.notes);
195-
// log.info(feeGroup.ccfriApplicationGuid);
196-
197-
let payload = {
178+
const childCareCategory = `/ccof_childcare_categories(${feeGroup.childCareCategory})`;
179+
const programYear = `/ccof_program_years(${feeGroup.programYear})`;
180+
const payload = {
198181
ccof_frequency: feeGroup.feeFrequency,
199182
'ccof_ChildcareCategory@odata.bind': childCareCategory,
200183
'ccof_ProgramYear@odata.bind': programYear,
184+
'ccof_ApplicationCCFRI@odata.bind': `/ccof_applicationccfris(${feeGroup.ccfriApplicationGuid})`,
201185
};
202186

203187
Object.assign(payload, {
@@ -214,13 +198,10 @@ async function upsertParentFees(req, res) {
214198
ccof_feb: feeGroup.febFee,
215199
ccof_mar: feeGroup.marFee,
216200
});
217-
let url = `_ccof_applicationccfri_value=${feeGroup.ccfriApplicationGuid},_ccof_childcarecategory_value=${feeGroup.childCareCategory},_ccof_programyear_value=${feeGroup.programYear} `;
201+
const url = `_ccof_applicationccfri_value=${feeGroup.ccfriApplicationGuid},_ccof_childcarecategory_value=${feeGroup.childCareCategory},_ccof_programyear_value=${feeGroup.programYear} `;
218202
try {
219-
let response = await patchOperationWithObjectId('ccof_application_ccfri_childcarecategories', url, payload);
220-
theResponse.push(res.status(HttpStatus.CREATED).json(response));
203+
await patchOperationWithObjectId('ccof_application_ccfri_childcarecategories', url, payload);
221204
} catch (e) {
222-
//log.info(e);
223-
theResponse.push(res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status));
224205
hasError = true;
225206
}
226207
}
@@ -229,33 +210,25 @@ async function upsertParentFees(req, res) {
229210
//if no notes, don't bother sending any requests. Even if left blank, front end will send over an empty string
230211
//so body[0].notes will always exist
231212

232-
let payload = {
213+
const payload = {
233214
ccof_informationccfri: body[0].notes,
234215
ccof_formcomplete: body[0].ccof_formcomplete,
235216
ccof_has_rfi: body[0].ccof_has_rfi,
236217
ccof_feecorrectccfri: body[0].existingFeesCorrect,
237218
ccof_chargefeeccfri: body[0].hasClosureFees,
238219
};
239220

240-
log.info(body[0].hasClosureFees);
241221
try {
242-
let response = await patchOperationWithObjectId('ccof_applicationccfris', body[0].ccfriApplicationGuid, payload);
243-
log.info('notesRes', response);
244-
theResponse.push(res.status(HttpStatus.CREATED).json(response));
222+
await patchOperationWithObjectId('ccof_applicationccfris', body[0].ccfriApplicationGuid, payload);
245223
} catch (e) {
246-
theResponse.push(res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status));
247224
hasError = true;
248225
}
249226

250227
//dates array will always exist - even if blank.
251228
//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"
252-
log.info(body[0].facilityClosureDates);
253229
try {
254-
let response = await postClosureDates(body[0].facilityClosureDates, body[0].ccfriApplicationGuid, res);
255-
//log.info('datesRes', response);
256-
theResponse.push(res.status(HttpStatus.CREATED).json(response));
230+
await postClosureDates(body[0].facilityClosureDates, body[0].ccfriApplicationGuid, res);
257231
} catch (e) {
258-
theResponse.push(res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status));
259232
hasError = true;
260233
}
261234

@@ -274,22 +247,20 @@ function formatTimeForBack(timeString) {
274247
}
275248

276249
async function postClosureDates(dates, ccfriApplicationGuid, res) {
277-
let retVal = [];
250+
const retVal = [];
278251

279252
//delete all the old closure dates from the application - otherwise we will get duplicates when we save
280-
let dynamicsClosureDates = await getCCFRIClosureDates(ccfriApplicationGuid);
253+
const dynamicsClosureDates = await getCCFRIClosureDates(ccfriApplicationGuid);
281254

282255
//don't bother trying to delete if there are no dates saved
283256
if (dynamicsClosureDates.length > 0) {
284257
try {
285258
await Promise.all(
286259
dynamicsClosureDates.map(async (date) => {
287260
await deleteOperationWithObjectId('ccof_application_ccfri_closures', date.closureDateId);
288-
//log.info(response);
289261
}),
290262
);
291263
} catch (e) {
292-
log.info('something broke when deleting existing closure dates.');
293264
log.info(e);
294265
//return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data? e.data : e?.status );
295266
}
@@ -299,14 +270,14 @@ async function postClosureDates(dates, ccfriApplicationGuid, res) {
299270
//if the user selects an end date, create a start and end date. else, use the only date for start and end.
300271
await Promise.all(
301272
dates.map(async (date) => {
302-
let payload = {
273+
const payload = {
303274
ccof_startdate: formatTimeForBack(date.formattedStartDate),
304275
ccof_paidclosure: date.feesPaidWhileClosed,
305276
ccof_enddate: date.formattedEndDate ? formatTimeForBack(date.formattedEndDate) : formatTimeForBack(date.formattedStartDate),
306277
ccof_comment: date.closureReason,
307278
'ccof_ApplicationCCFRI@odata.bind': `/ccof_applicationccfris(${ccfriApplicationGuid})`,
308279
};
309-
let response = await postOperation('ccof_application_ccfri_closures', payload);
280+
const response = await postOperation('ccof_application_ccfri_closures', payload);
310281
retVal.push(response);
311282
}),
312283
);
@@ -319,13 +290,13 @@ async function postClosureDates(dates, ccfriApplicationGuid, res) {
319290

320291
async function getECEWEApplication(req, res) {
321292
try {
322-
let operation =
293+
const operation =
323294
'ccof_applications(' +
324295
req.params.applicationId +
325296
')?$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)';
326297
let eceweApp = await getOperation(operation);
327298
eceweApp = new MappableObjectForFront(eceweApp, ECEWEApplicationMappings);
328-
let forFrontFacilities = [];
299+
const forFrontFacilities = [];
329300
Object.values(eceweApp.data.facilities).forEach((value) => forFrontFacilities.push(new MappableObjectForFront(value, ECEWEFacilityMappings).data));
330301
eceweApp.data.facilities = forFrontFacilities;
331302
return res.status(HttpStatus.OK).json(eceweApp);
@@ -342,38 +313,38 @@ async function updateECEWEApplication(req, res) {
342313
application.ccof_ecewe_employeeunion = application.ccof_ecewe_optin == 0 ? null : application.ccof_ecewe_employeeunion;
343314
try {
344315
log.verbose('updateECEWEApplication: payload', application);
345-
let response = await patchOperationWithObjectId('ccof_applications', req.params.applicationId, application);
316+
const response = await patchOperationWithObjectId('ccof_applications', req.params.applicationId, application);
346317
return res.status(HttpStatus.OK).json(response);
347318
} catch (e) {
348319
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status);
349320
}
350321
}
351322

352323
async function updateECEWEFacilityApplication(req, res) {
353-
let facilities = req.body;
354-
let forBackFacilities = [];
324+
const facilities = req.body;
325+
const forBackFacilities = [];
355326
let response;
356327
Object.values(facilities).forEach((value) => forBackFacilities.push(new MappableObjectForBack(value, ECEWEFacilityMappings).data));
357328
let eceweApplicationId;
358329
try {
359-
for (let key in forBackFacilities) {
330+
for (const key in forBackFacilities) {
360331
// add join attributes for application and facility
361332
forBackFacilities[key]['ccof_application@odata.bind'] = '/ccof_applications(' + req.params.applicationId + ')';
362333
forBackFacilities[key]['ccof_Facility@odata.bind'] = '/accounts(' + forBackFacilities[key]._ccof_facility_value + ')';
363334
eceweApplicationId = forBackFacilities[key].ccof_applicationeceweid;
364-
let changeRequestNewFacilityId = forBackFacilities[key].ccof_change_request_new_facilityid;
335+
const changeRequestNewFacilityId = forBackFacilities[key].ccof_change_request_new_facilityid;
365336
// remove attributes that are already used in payload join (above) and not needed.
366337
delete forBackFacilities[key].ccof_applicationeceweid;
367338
delete forBackFacilities[key]._ccof_facility_value;
368339
delete forBackFacilities[key].ccof_change_request_new_facilityid;
369340

370-
let facility = forBackFacilities[key];
341+
const facility = forBackFacilities[key];
371342
if (eceweApplicationId) {
372343
// send PATCH (update existing ECEWE facility)
373344
response = await patchOperationWithObjectId('ccof_applicationecewes', eceweApplicationId, facility);
374345
} else {
375346
// send POST (create a new ECEWE facility)
376-
let operation = 'ccof_applicationecewes';
347+
const operation = 'ccof_applicationecewes';
377348
response = await postOperation(operation, facility);
378349
facilities[key].eceweApplicationId = response;
379350
//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) {
391362
/* Get the user declaration for a given application id. */
392363
async function getDeclaration(req, res) {
393364
try {
394-
let operation = 'ccof_applications(' + req.params.applicationId + ')?$select=ccof_consent,ccof_submittedby,ccof_declarationastatus,ccof_declarationbstatus,statuscode';
365+
const operation = 'ccof_applications(' + req.params.applicationId + ')?$select=ccof_consent,ccof_submittedby,ccof_declarationastatus,ccof_declarationbstatus,statuscode';
395366
let declaration = await getOperation(operation);
396367
declaration = new MappableObjectForFront(declaration, DeclarationMappings);
397368
return res.status(HttpStatus.OK).json(declaration);
@@ -405,7 +376,7 @@ async function getDeclaration(req, res) {
405376
async function submitApplication(req, res) {
406377
let declaration = new MappableObjectForBack(req.body, DeclarationMappings);
407378
declaration.data.statuscode = APPLICATION_STATUS_CODES.SUBMITTED;
408-
let ccfriFacilitiesToLock = JSON.parse(JSON.stringify(declaration));
379+
const ccfriFacilitiesToLock = JSON.parse(JSON.stringify(declaration));
409380
declaration = declaration.toJSON();
410381
try {
411382
delete declaration.facilities;

0 commit comments

Comments
 (0)