Skip to content

Commit

Permalink
OFMCC-364 - fix formatting error
Browse files Browse the repository at this point in the history
  • Loading branch information
vietle-cgi committed Nov 4, 2023
1 parent 7870167 commit c2bbb73
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 243 deletions.
147 changes: 79 additions & 68 deletions backend/src/components/lookup.js
Original file line number Diff line number Diff line change
@@ -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 = [
{
Expand All @@ -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 = {
Expand All @@ -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) {
Expand All @@ -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,
}
18 changes: 8 additions & 10 deletions backend/src/components/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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['[email protected]'] = `/ofm_request_categories(${data?.requestCategoryId})`
assistanceRequest['[email protected]'] = `/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({
'[email protected]' : `/accounts(${facility.facilityId})`,
'[email protected]': `/accounts(${facility.facilityId})`,
})
})
return assistanceRequest;
return assistanceRequest
}

function sortByPropertyDesc(property) {
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -78,13 +77,12 @@ 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)
}
}

module.exports = {
getMessages,
updateMessageLastOpenedTime,
createNewAssistanceRequest,
};

}
27 changes: 13 additions & 14 deletions backend/src/routes/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
6 changes: 3 additions & 3 deletions backend/src/util/mapping/Mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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' },
Expand All @@ -62,4 +62,4 @@ module.exports = {
UserProfileFacilityMappings,
RequestCategoryMappings,
AssistanceRequestMappings,
};
}
Loading

0 comments on commit c2bbb73

Please sign in to comment.