From 926074d82d0443311219b6779a517c43389d0487 Mon Sep 17 00:00:00 2001 From: Le Date: Wed, 7 Aug 2024 09:49:45 -0700 Subject: [PATCH 1/2] ofmcc-5446 - fix blank operation hour error --- backend/src/components/licences.js | 20 ++++++++++++------- .../components/licences/LicenceDetails.vue | 13 ++---------- frontend/src/utils/format.js | 1 + frontend/src/utils/rules.js | 6 +++--- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/backend/src/components/licences.js b/backend/src/components/licences.js index abf3e8ef..f0d4f66e 100644 --- a/backend/src/components/licences.js +++ b/backend/src/components/licences.js @@ -1,19 +1,26 @@ 'use strict' -const { getOperation, patchOperationWithObjectId } = require('./utils') +const { getOperation, patchOperationWithObjectId, handleError } = require('./utils') const { MappableObjectForFront, MappableObjectForBack } = require('../util/mapping/MappableObject') const { LicenceDetailsMappings } = require('../util/mapping/Mappings') const HttpStatus = require('http-status-codes') -const log = require('./logger') async function getLicenceDetails(req, res) { try { - const operation = `ofm_licence_details?$select=ofm_licence_detailid,ofm_licence_type,ofm_licence_spaces,ofm_operational_spaces,ofm_enrolled_spaces,ofm_operation_from_time,ofm_operations_to_time,ofm_week_days,ofm_weeks_in_operation,ofm_care_type,ofm_overnight_care,ofm_apply_room_split_condition,ofm_room_split_details,statuscode,statecode&$filter=(_ofm_licence_value eq ${req.params.licenceId}) and (statecode eq 0)` + const operation = `ofm_licence_details?$select=ofm_licence_detailid,ofm_licence_type,ofm_licence_spaces,ofm_operational_spaces,ofm_enrolled_spaces,ofm_operation_from_time,ofm_operations_to_time,ofm_operation_hours_from,ofm_operation_hours_to,ofm_week_days,ofm_weeks_in_operation,ofm_care_type,ofm_overnight_care,ofm_apply_room_split_condition,ofm_room_split_details,statuscode,statecode&$filter=(_ofm_licence_value eq ${req.params.licenceId}) and (statecode eq 0)` const response = await getOperation(operation) const licenceDetails = [] - response?.value?.forEach((item) => licenceDetails.push(new MappableObjectForFront(item, LicenceDetailsMappings).toJSON())) + response?.value?.forEach((item) => { + const mappedLicenceDetails = new MappableObjectForFront(item, LicenceDetailsMappings).toJSON() + // XXX (OFMCC-5436) - In CRM, ofm_operation_from_time (ofm_operations_to_time) gets the hours from ofm_operation_hours_from (ofm_operation_hours_to). + // If ofm_operation_hours_from (ofm_operation_hours_to) is null, CRM set ofm_operation_from_time (ofm_operations_to_time) to 12:00 AM as default. + // Therefore, we need this logic to overwrite that default value. + mappedLicenceDetails.operationFromTime = mappedLicenceDetails.updatableOperationFromTime ? mappedLicenceDetails.operationFromTime : null + mappedLicenceDetails.operationToTime = mappedLicenceDetails.updatableOperationToTime ? mappedLicenceDetails.operationToTime : null + licenceDetails.push(mappedLicenceDetails) + }) return res.status(HttpStatus.OK).json(licenceDetails) } catch (e) { - return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status) + handleError(res, e) } } @@ -23,8 +30,7 @@ async function updateLicenceDetails(req, res) { const response = await patchOperationWithObjectId('ofm_licence_details', req.params.licenceDetailId, payload) return res.status(HttpStatus.OK).json(response) } catch (e) { - log.error(e) - return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status) + handleError(res, e) } } diff --git a/frontend/src/components/licences/LicenceDetails.vue b/frontend/src/components/licences/LicenceDetails.vue index 314b149b..e3d27d78 100644 --- a/frontend/src/components/licences/LicenceDetails.vue +++ b/frontend/src/components/licences/LicenceDetails.vue @@ -184,13 +184,12 @@ @update:modelValue="update(licenceDetail)" /> @@ -266,7 +265,6 @@ import AppLabel from '@/components/ui/AppLabel.vue' import AppNumberInput from '@/components/ui/AppNumberInput.vue' import AppTimeInput from '@/components/ui/AppTimeInput.vue' import AppYesNoInput from '@/components/ui/AppYesNoInput.vue' -import format from '@/utils/format' import rules from '@/utils/rules' import { useAppStore } from '@/stores/app' import { BLANK_FIELD, DAYS_OF_WEEK } from '@/utils/constants' @@ -299,8 +297,6 @@ export default { data() { return { panel: [], - rules, - isFormComplete: false, } }, @@ -330,6 +326,7 @@ export default { separator: ',', precision: 0, } + this.rules = rules }, async mounted() { @@ -383,12 +380,6 @@ export default { licenceDetail.weekDays = DAYS_OF_WEEK.map((day) => day.value) } }, - - getErrorMessagesForOperationTime(licenceDetail) { - const from = format.convertTimeToDateTimeFormat(licenceDetail?.operationFromTime) - const to = format.convertTimeToDateTimeFormat(licenceDetail?.operationToTime) - return from >= to ? 'Hours To must be after Hours From' : '' - }, }, } diff --git a/frontend/src/utils/format.js b/frontend/src/utils/format.js index 94607141..8e3b1f4f 100644 --- a/frontend/src/utils/format.js +++ b/frontend/src/utils/format.js @@ -37,6 +37,7 @@ function convertUTCDatetoPSTDate(date) { - Output: 2024-08-06 13:00:00 PDT */ function convertTimeToDateTimeFormat(time) { + if (!time) return null const hours = time?.split(':')[0] const minutes = time?.split(':')[1] return momentTZ().tz(TIME_ZONE).hours(hours).minutes(minutes).seconds(0).milliseconds(0) diff --git a/frontend/src/utils/rules.js b/frontend/src/utils/rules.js index bd0d358b..52e3f10d 100644 --- a/frontend/src/utils/rules.js +++ b/frontend/src/utils/rules.js @@ -29,15 +29,15 @@ const rules = { } return true }, + validHourTo(hourFrom) { + return (v) => !v || v > hourFrom || `Hours To must be after Hours From` + }, max(number) { return (v) => !v || v <= number || `Max exceeded: ${number.toLocaleString('en-ca')}` }, min(number) { return (v) => !v || v >= number || `Min exceeded: ${number.toLocaleString('en-ca')}` }, - greaterThan(value) { - return (v) => !v || v > value || `Must be greater than: ${value}` - }, maxLength(number) { return (v) => !v || v.length <= number || 'Max length exceeded' }, From 80d437c24a3ced399f630c33fca8404b8c06534a Mon Sep 17 00:00:00 2001 From: Le Date: Wed, 7 Aug 2024 09:52:21 -0700 Subject: [PATCH 2/2] ofmcc-5446 - eslint error change to single quote --- frontend/src/utils/rules.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/utils/rules.js b/frontend/src/utils/rules.js index 52e3f10d..234b141b 100644 --- a/frontend/src/utils/rules.js +++ b/frontend/src/utils/rules.js @@ -30,7 +30,7 @@ const rules = { return true }, validHourTo(hourFrom) { - return (v) => !v || v > hourFrom || `Hours To must be after Hours From` + return (v) => !v || v > hourFrom || 'Hours To must be after Hours From' }, max(number) { return (v) => !v || v <= number || `Max exceeded: ${number.toLocaleString('en-ca')}`