Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ofmcc-5446 - fix blank operation hour error #314

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions backend/src/components/licences.js
Original file line number Diff line number Diff line change
@@ -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)
}
}

Expand All @@ -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)
}
}

Expand Down
13 changes: 2 additions & 11 deletions frontend/src/components/licences/LicenceDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,12 @@
@update:modelValue="update(licenceDetail)" />
<AppTimeInput
v-model="licenceDetail.operationToTime"
:rules="[...rules.required, rules.greaterThan(licenceDetail.operationFromTime)]"
:rules="[...rules.required, rules.validHourTo(licenceDetail.operationFromTime)]"
:disabled="readOnly"
:hide-details="readOnly"
label="To"
min-width="150px"
max-width="150px"
:error-messages="getErrorMessagesForOperationTime(licenceDetail)"
class="pr-2"
@update:modelValue="update(licenceDetail)" />
</v-row>
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -299,8 +297,6 @@ export default {
data() {
return {
panel: [],
rules,
isFormComplete: false,
}
},

Expand Down Expand Up @@ -330,6 +326,7 @@ export default {
separator: ',',
precision: 0,
}
this.rules = rules
},

async mounted() {
Expand Down Expand Up @@ -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' : ''
},
},
}
</script>
1 change: 1 addition & 0 deletions frontend/src/utils/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/utils/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
Expand Down
Loading