diff --git a/backend/src/components/lookup.js b/backend/src/components/lookup.js index d1dbc716..1cb38c4d 100644 --- a/backend/src/components/lookup.js +++ b/backend/src/components/lookup.js @@ -1,41 +1,41 @@ -'use strict'; -const {getOperation, getLabelFromValue, } = require('./utils'); -const HttpStatus = require('http-status-codes'); -const _ = require ('lodash'); -const cache = require('memory-cache'); -const { PROGRAM_YEAR_STATUS_CODES, ORGANIZATION_PROVIDER_TYPES, CHANGE_REQUEST_TYPES } = require('../util/constants'); -const { ProgramYearMappings, SystemMessagesMappings, RequestCategoryMappings } = require('../util/mapping/Mappings'); -const { MappableObjectForFront } = require('../util/mapping/MappableObject'); +'use strict' +const { getOperation, getLabelFromValue } = require('./utils') +const HttpStatus = require('http-status-codes') +const _ = require('lodash') +const cache = require('memory-cache') +const { PROGRAM_YEAR_STATUS_CODES, ORGANIZATION_PROVIDER_TYPES, CHANGE_REQUEST_TYPES } = require('../util/constants') +const { ProgramYearMappings, SystemMessagesMappings, RequestCategoryMappings } = require('../util/mapping/Mappings') +const { MappableObjectForFront } = require('../util/mapping/MappableObject') const log = require('../components/logger') -const lookupCache = new cache.Cache(); +const lookupCache = new cache.Cache() const organizationType = [ { name: 'Non-Profit Society', - id: 100000000 + id: 100000000, }, { name: 'Public Institution (college/university)', - id: 100000001 + id: 100000001, }, { name: 'Registered Company', - id: 100000002 + id: 100000002, }, { name: 'Local Government', - id: 100000003 + id: 100000003, }, { name: 'First Nations Government', - id: 100000004 + id: 100000004, }, { name: 'Sole Proprietorship or Partnership', - id: 100000005 - } -]; + id: 100000005, + }, +] const fundingModelType = [ { @@ -50,7 +50,7 @@ const fundingModelType = [ id: 100000002, description: 'Some of our facilities have both non-provincially funded ECEs that do not receive Low-Wage Redress Funding AND provincially funded ECEs receiving Low-Wage Redress Funding', }, -]; +] function parseProgramYear(value) { let programYears = { @@ -59,59 +59,70 @@ function parseProgramYear(value) { previous: undefined, renewal: undefined, newApp: undefined, - list: [] - }; - value.forEach(item => { - let p = new MappableObjectForFront(item, ProgramYearMappings).data; - let currentStatus = p.status; - p.status = getLabelFromValue(p.status, PROGRAM_YEAR_STATUS_CODES); + list: [], + } + value.forEach((item) => { + let p = new MappableObjectForFront(item, ProgramYearMappings).data + let currentStatus = p.status + p.status = getLabelFromValue(p.status, PROGRAM_YEAR_STATUS_CODES) if (currentStatus == PROGRAM_YEAR_STATUS_CODES.CURRENT) { - programYears.current = p; + programYears.current = p } else if (currentStatus == PROGRAM_YEAR_STATUS_CODES.FUTURE) { - programYears.future = p; + programYears.future = p } - programYears.list.push(p); - }); - programYears.previous = programYears.list.find(p => p.programYearId == programYears.current.previousYearId); - programYears.list.sort((a,b) => { return b.order - a.order; } ); - programYears.renewal = programYears.future ? programYears.future: programYears.list[0]; + programYears.list.push(p) + }) + programYears.previous = programYears.list.find((p) => p.programYearId == programYears.current.previousYearId) + programYears.list.sort((a, b) => { + return b.order - a.order + }) + programYears.renewal = programYears.future ? programYears.future : programYears.list[0] // Set the program year for a new application if (programYears.current?.intakeEnd) { - const intakeDate = new Date(programYears.current?.intakeEnd); - programYears.newApp = new Date() > intakeDate ? programYears.renewal : programYears.current; + const intakeDate = new Date(programYears.current?.intakeEnd) + programYears.newApp = new Date() > intakeDate ? programYears.renewal : programYears.current } else { - programYears.newApp = programYears.current; + programYears.newApp = programYears.current } - - - - return programYears; + return programYears } async function getLicenseCategory() { - let resData = lookupCache.get('licenseCategory'); + let resData = lookupCache.get('licenseCategory') if (!resData) { - resData = {}; - let licenseCategory = await getOperation('ccof_license_categories'); - licenseCategory = licenseCategory.value.filter(item => item.statuscode ==1).map(item => { return _.pick(item, ['ccof_license_categoryid', 'ccof_providertype', 'ccof_name', 'ccof_categorynumber']); }); - resData.groupLicenseCategory = licenseCategory.filter( item => item.ccof_providertype == ORGANIZATION_PROVIDER_TYPES.GROUP).sort((a,b) => { return a.ccof_categorynumber - b.ccof_categorynumber; } ); - resData.familyLicenseCategory = licenseCategory.filter( item => item.ccof_providertype == ORGANIZATION_PROVIDER_TYPES.FAMILY).sort((a,b) => { return a.ccof_categorynumber - b.ccof_categorynumber; } ); - lookupCache.put('licenseCategory', resData, 60 * 60 * 1000); + resData = {} + let licenseCategory = await getOperation('ccof_license_categories') + licenseCategory = licenseCategory.value + .filter((item) => item.statuscode == 1) + .map((item) => { + return _.pick(item, ['ccof_license_categoryid', 'ccof_providertype', 'ccof_name', 'ccof_categorynumber']) + }) + resData.groupLicenseCategory = licenseCategory + .filter((item) => item.ccof_providertype == ORGANIZATION_PROVIDER_TYPES.GROUP) + .sort((a, b) => { + return a.ccof_categorynumber - b.ccof_categorynumber + }) + resData.familyLicenseCategory = licenseCategory + .filter((item) => item.ccof_providertype == ORGANIZATION_PROVIDER_TYPES.FAMILY) + .sort((a, b) => { + return a.ccof_categorynumber - b.ccof_categorynumber + }) + lookupCache.put('licenseCategory', resData, 60 * 60 * 1000) } - return resData; + return resData } async function getRequestCategories() { - let requestCategories = lookupCache.get('requestCategories'); + let requestCategories = lookupCache.get('requestCategories') if (!requestCategories) { - requestCategories = []; - let response = await getOperation('ofm_request_categories'); - response?.value?.forEach(item => requestCategories.push(new MappableObjectForFront(item, RequestCategoryMappings))); - lookupCache.put('requestCategories', requestCategories, 60 * 60 * 1000); + requestCategories = [] + let response = await getOperation('ofm_request_categories') + response?.value?.forEach((item) => requestCategories.push(new MappableObjectForFront(item, RequestCategoryMappings))) + lookupCache.put('requestCategories', requestCategories, 60 * 60 * 1000) } - return requestCategories; + return requestCategories } async function getLookupInfo(req, res) { @@ -124,34 +135,34 @@ async function getLookupInfo(req, res) { * 4 - Historica */ try { - let resData = lookupCache.get('lookups'); + let resData = lookupCache.get('lookups') if (!resData) { - let requestCategories = await getRequestCategories(); + let requestCategories = await getRequestCategories() resData = { - 'requestCategories': requestCategories, - }; - lookupCache.put('lookups', resData, 60 * 60 * 1000); + requestCategories: requestCategories, + } + lookupCache.put('lookups', resData, 60 * 60 * 1000) } - return res.status(HttpStatus.OK).json(resData); + return res.status(HttpStatus.OK).json(resData) } catch (e) { - return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status); + return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status) } } async function getSystemMessages(req, res) { - let systemMessages = lookupCache.get('systemMessages'); + let systemMessages = lookupCache.get('systemMessages') if (!systemMessages) { - let currentTime = (new Date()).toISOString(); - systemMessages = []; - let resData = await getOperation(`ccof_systemmessages?$filter=(ccof_startdate le ${currentTime} and ccof_enddate ge ${currentTime})`); - resData?.value.forEach(message => systemMessages.push(new MappableObjectForFront(message, SystemMessagesMappings).data)); - lookupCache.put('systemMessages', systemMessages, 60 * 60 * 1000); + let currentTime = new Date().toISOString() + systemMessages = [] + let resData = await getOperation(`ccof_systemmessages?$filter=(ccof_startdate le ${currentTime} and ccof_enddate ge ${currentTime})`) + resData?.value.forEach((message) => systemMessages.push(new MappableObjectForFront(message, SystemMessagesMappings).data)) + lookupCache.put('systemMessages', systemMessages, 60 * 60 * 1000) } - return res.status(HttpStatus.OK).json(systemMessages); + return res.status(HttpStatus.OK).json(systemMessages) } module.exports = { getLookupInfo, getLicenseCategory, - getSystemMessages -}; + getSystemMessages, +} diff --git a/backend/src/components/message.js b/backend/src/components/message.js index 99978a93..1bce6b6c 100644 --- a/backend/src/components/message.js +++ b/backend/src/components/message.js @@ -16,17 +16,16 @@ function mapMessageObjectForFront(data) { function mapAssistanceRequestObjectForBack(data) { let assistanceRequest = new MappableObjectForBack(data, AssistanceRequestMappings).toJSON() - if (assistanceRequest['ofm_contact_method'] == '1') - delete assistanceRequest['ofm_telephone'] + if (assistanceRequest['ofm_contact_method'] == '1') delete assistanceRequest['ofm_telephone'] assistanceRequest['ofm_request_category@odata.bind'] = `/ofm_request_categories(${data?.requestCategoryId})` assistanceRequest['ofm_contact@odata.bind'] = `/contacts(${data?.contactId})` - assistanceRequest['ofm_facility_request_request'] = []; - data?.facilities?.forEach(facility => { + assistanceRequest['ofm_facility_request_request'] = [] + data?.facilities?.forEach((facility) => { assistanceRequest['ofm_facility_request_request'].push({ - 'ofm_facility@odata.bind' : `/accounts(${facility.facilityId})`, + 'ofm_facility@odata.bind': `/accounts(${facility.facilityId})`, }) }) - return assistanceRequest; + return assistanceRequest } function sortByPropertyDesc(property) { @@ -67,7 +66,7 @@ async function updateMessageLastOpenedTime(req, res) { let response = await patchOperationWithObjectId('emails', req.params.messageId, req.body) return res.status(HttpStatus.OK).json(response) } catch (e) { - return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data? e.data : e?.status ) + return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status) } } @@ -78,7 +77,7 @@ async function createNewAssistanceRequest(req, res) { response = new MappableObjectForFront(response, AssistanceRequestMappings).toJSON() return res.status(HttpStatus.OK).json(response) } catch (e) { - return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data? e.data : e?.status ) + return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status) } } @@ -86,5 +85,4 @@ module.exports = { getMessages, updateMessageLastOpenedTime, createNewAssistanceRequest, -}; - +} diff --git a/backend/src/routes/message.js b/backend/src/routes/message.js index ff7b3f13..23549646 100644 --- a/backend/src/routes/message.js +++ b/backend/src/routes/message.js @@ -6,34 +6,34 @@ const isValidBackendToken = auth.isValidBackendToken() const { getMessages, updateMessageLastOpenedTime, createNewAssistanceRequest } = require('../components/message') const { param, validationResult, checkSchema } = require('express-validator') -module.exports = router; +module.exports = router const newAssistanceRequestSchema = { contactId: { in: ['body'], - exists: { errorMessage: '[contactId] is required', } + exists: { errorMessage: '[contactId] is required' }, }, requestCategoryId: { in: ['body'], - exists: { errorMessage: '[requestCategoryId] is required', } + exists: { errorMessage: '[requestCategoryId] is required' }, }, subject: { in: ['body'], - exists: { errorMessage: '[subject] is required', } + exists: { errorMessage: '[subject] is required' }, }, description: { in: ['body'], - exists: { errorMessage: '[description] is required', } + exists: { errorMessage: '[description] is required' }, }, facilities: { in: ['body'], - exists: { errorMessage: '[facilities] is required', } + exists: { errorMessage: '[facilities] is required' }, }, contactMethod: { in: ['body'], - exists: { errorMessage: '[contactMethod] is required', } - } -}; + exists: { errorMessage: '[contactMethod] is required' }, + }, +} /** * Get messages filtered by contactid @@ -54,10 +54,9 @@ router.put('/:messageId', passport.authenticate('jwt', { session: false }), isVa /** * Create a new Assistance Request */ -router.post('/newAssistanceRequest', passport.authenticate('jwt', {session: false}),isValidBackendToken, [ - checkSchema(newAssistanceRequestSchema)], (req, res) => { - validationResult(req).throw(); - return createNewAssistanceRequest(req, res); -}); +router.post('/newAssistanceRequest', passport.authenticate('jwt', { session: false }), isValidBackendToken, [checkSchema(newAssistanceRequestSchema)], (req, res) => { + validationResult(req).throw() + return createNewAssistanceRequest(req, res) +}) module.exports = router diff --git a/backend/src/util/mapping/Mappings.js b/backend/src/util/mapping/Mappings.js index af12f844..b3a6e226 100644 --- a/backend/src/util/mapping/Mappings.js +++ b/backend/src/util/mapping/Mappings.js @@ -35,7 +35,7 @@ const UserProfileFacilityMappings = [ const RequestCategoryMappings = [ { back: 'ofm_name', front: 'categoryName' }, { back: 'ofm_request_categoryid', front: 'categoryId' }, -]; +] const AssistanceRequestMappings = [ { back: 'ofm_subject', front: 'subject' }, @@ -44,7 +44,7 @@ const AssistanceRequestMappings = [ { back: 'ofm_telephone', front: 'phone' }, { back: 'ofm_assistance_requestid', front: 'assistanceRequestId' }, { back: 'ofm_name', front: 'referenceNumber' }, -]; +] const NotificationMappings = [ { back: 'activityid', front: 'notificationId' }, @@ -62,4 +62,4 @@ module.exports = { UserProfileFacilityMappings, RequestCategoryMappings, AssistanceRequestMappings, -}; +} diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 7e3e56cc..a12cd0cc 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -10,8 +10,7 @@ - + @@ -31,7 +30,7 @@ import TheNavBar from '@/components/TheNavBar.vue' import TheSnackBar from '@/components/TheSnackBar.vue' import { useAppStore } from '@/stores/app' import { useAuthStore } from '@/stores/auth' -import HttpStatus from 'http-status-codes'; +import HttpStatus from 'http-status-codes' export default { name: 'App', @@ -73,20 +72,20 @@ export default { async created() { //this.setLoading(true); this.getJwtToken() - .then(() => Promise.all([this.getLookupInfo()])) - .catch((e) => { - if (!e.response || e.response.status !== HttpStatus.UNAUTHORIZED) { - // this.logout() - console.log(e); - this.$router.replace({ - name: 'error', - query: { message: `500_${e.data || 'ServerError'}` }, - }) - } - }) - .finally(() => { - // this.setLoading(false); - }) + .then(() => Promise.all([this.getLookupInfo()])) + .catch((e) => { + if (!e.response || e.response.status !== HttpStatus.UNAUTHORIZED) { + // this.logout() + console.log(e) + this.$router.replace({ + name: 'error', + query: { message: `500_${e.data || 'ServerError'}` }, + }) + } + }) + .finally(() => { + // this.setLoading(false); + }) // this.setLoading(false); }, methods: { diff --git a/frontend/src/common/apiService.js b/frontend/src/common/apiService.js index 167c0a55..0380104d 100644 --- a/frontend/src/common/apiService.js +++ b/frontend/src/common/apiService.js @@ -108,11 +108,11 @@ export default { }, async getLookupInfo() { - try{ - return await apiAxios.get(ApiRoutes.LOOKUP); - } catch(e) { - console.log(`Failed to get from Nodejs getLookups API - ${e}`); - throw e; + try { + return await apiAxios.get(ApiRoutes.LOOKUP) + } catch (e) { + console.log(`Failed to get from Nodejs getLookups API - ${e}`) + throw e } }, } diff --git a/frontend/src/components/messages/MessagesTab.vue b/frontend/src/components/messages/MessagesTab.vue index e9093fac..0a42c600 100644 --- a/frontend/src/components/messages/MessagesTab.vue +++ b/frontend/src/components/messages/MessagesTab.vue @@ -1,20 +1,17 @@ - + diff --git a/frontend/src/components/messages/NewRequestConfirmationDialog.vue b/frontend/src/components/messages/NewRequestConfirmationDialog.vue index 1668f738..394ae45a 100644 --- a/frontend/src/components/messages/NewRequestConfirmationDialog.vue +++ b/frontend/src/components/messages/NewRequestConfirmationDialog.vue @@ -1,15 +1,10 @@