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

Removing redundant organization code inherited during scaffolding OFM… #61

Merged
merged 4 commits into from
Dec 18, 2023
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
4 changes: 0 additions & 4 deletions backend/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const configRouter = require('./routes/config')
const documentsRouter = require('./routes/documents')
const messageRouter = require('./routes/message')
const notificationRouter = require('./routes/notification')
const organizationRouter = require('./routes/organization')
const applicationsRouter = require('./routes/applications')

const connectRedis = require('connect-redis')
Expand Down Expand Up @@ -194,9 +193,6 @@ apiRouter.use('/messages', messageRouter)
apiRouter.use('/notifications', notificationRouter)
apiRouter.use('/applications', applicationsRouter)

//TODO: Router from MyCCS only here for 1st backend iteration example. To be removed ...
apiRouter.use('/organization', organizationRouter)

//Handle 500 error
app.use((err, _req, res, next) => {
//This is from the ResultValidation
Expand Down
121 changes: 1 addition & 120 deletions backend/src/components/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,117 +3,12 @@ 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, UserRoleMappings } = require('../util/mapping/Mappings')
const { RequestCategoryMappings } = require('../util/mapping/Mappings')
const { MappableObjectForFront } = require('../util/mapping/MappableObject')
const log = require('../components/logger')

const lookupCache = new cache.Cache()

const organizationType = [
{
name: 'Non-Profit Society',
id: 100000000,
},
{
name: 'Public Institution (college/university)',
id: 100000001,
},
{
name: 'Registered Company',
id: 100000002,
},
{
name: 'Local Government',
id: 100000003,
},
{
name: 'First Nations Government',
id: 100000004,
},
{
name: 'Sole Proprietorship or Partnership',
id: 100000005,
},
]

const fundingModelType = [
{
id: 100000000,
description: 'All of our facilities have provincially funded ECEs and receive Low-Wage Redress Funding',
},
{
id: 100000001,
description: 'All of our facilities have only non-provincially funded ECEs and do not receive Low-Wage Redress Funding',
},
{
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 = {
current: undefined,
future: undefined,
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)
if (currentStatus == PROGRAM_YEAR_STATUS_CODES.CURRENT) {
programYears.current = p
} else if (currentStatus == PROGRAM_YEAR_STATUS_CODES.FUTURE) {
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]

// 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
} else {
programYears.newApp = programYears.current
}

return programYears
}

async function getLicenseCategory() {
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)
}
return resData
}

async function getRequestCategories() {
let requestCategories = lookupCache.get('requestCategories')
if (!requestCategories) {
Expand Down Expand Up @@ -160,20 +55,6 @@ async function getLookupInfo(req, res) {
}
}

async function getSystemMessages(req, res) {
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)
}
return res.status(HttpStatus.OK).json(systemMessages)
}

module.exports = {
getLookupInfo,
getLicenseCategory,
getSystemMessages,
}
110 changes: 0 additions & 110 deletions backend/src/components/organization.js

This file was deleted.

6 changes: 3 additions & 3 deletions backend/src/components/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const ApiError = require('./error')
const axios = require('axios')
const HttpStatus = require('http-status-codes')
const log = require('../components/logger')
// TODO... const { ORGANIZATION_PROVIDER_TYPES} = require('../util/constants')

const {
FacilityMappings,
UserFacilityMappings,
Expand Down Expand Up @@ -118,8 +118,8 @@ async function getDynamicsUserByEmail(req) {
//If for some reason, an email is not associated with the IDIR, just use IDR@gov.bc.ca
email = `${req.session.passport.user._json.idir_username}@gov.bc.ca`
}
// eslint-disable-next-line quotes,
email.includes("'") ? (email = email.replace("'", "''")) : email
// Sanitize email to prevent SQL injection
email = email.replace(/'/g, "''")
try {
let response = await getOperation(`systemusers?$select=firstname,domainname,lastname&$filter=internalemailaddress eq '${email}'`)
return response
Expand Down
56 changes: 23 additions & 33 deletions backend/src/config/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict';
const nconf = require('nconf');
const dotenv = require('dotenv');
const path = require('path');
dotenv.config();
'use strict'
const nconf = require('nconf')
const dotenv = require('dotenv')
const path = require('path')
dotenv.config()

const env = process.env.NODE_ENV || 'local';
const env = process.env.NODE_ENV || 'local'

nconf.argv()
nconf
.argv()
.env()
.file({ file: path.join(__dirname, `${env}.json`) });
.file({ file: path.join(__dirname, `${env}.json`) })

//injects environment variables into the json file
nconf.overrides({
Expand All @@ -17,11 +18,9 @@ nconf.overrides({
server: {
logLevel: process.env.LOG_LEVEL,
morganFormat: 'dev',
port: 8080
}
});


port: 8080,
},
})

nconf.defaults({
environment: env,
Expand All @@ -31,15 +30,15 @@ nconf.defaults({
frontend: process.env.SERVER_FRONTEND,
logLevel: process.env.LOG_LEVEL,
morganFormat: 'dev',
port: process.env.SERVER_PORT
port: process.env.SERVER_PORT,
},
oidc: {
publicKey: process.env.SOAM_PUBLIC_KEY,
clientId: process.env.SOAM_CLIENT_ID,
clientSecret: process.env.SOAM_CLIENT_SECRET,
clientIdIDIR: process.env.SOAM_CLIENT_ID_IDIR,
clientSecretIDIR: process.env.SOAM_CLIENT_SECRET_IDIR,
discovery: process.env.SOAM_DISCOVERY
discovery: process.env.SOAM_DISCOVERY,
},
secureExchange: {
apiEndpoint: process.env.CCOF_API_ENDPOINT,
Expand All @@ -48,33 +47,24 @@ nconf.defaults({
privateKey: process.env.UI_PRIVATE_KEY,
publicKey: process.env.UI_PUBLIC_KEY,
audience: process.env.SERVER_FRONTEND,
issuer: process.env.ISSUER
},
organization: {
apiEndpoint: process.env.ORGANIZATION_API_ENDPOINT,
issuer: process.env.ISSUER,
},
dynamicsApi: {
apiEndpoint: process.env.D365_API_ENDPOINT,
apiKeyHeader: process.env.D365_API_KEY_HEADER,
apiKeyValue: process.env.D365_API_KEY_VALUE
apiKeyValue: process.env.D365_API_KEY_VALUE,
},
messaging:{
natsUrl:process.env.NATS_URL,
natsCluster:process.env.NATS_CLUSTER
},
ccof: {
rootURL: process.env.CCOF_API_ENDPOINT,
organizationUR: process.env.CCOF_API_ENDPOINT + '/organizations',
ccofFormURL: process.env.CCOF_API_ENDPOINT + '/ccof'
messaging: {
natsUrl: process.env.NATS_URL,
natsCluster: process.env.NATS_CLUSTER,
},
redis: {
use: process.env.USE_REDIS,
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
password: process.env.REDIS_PASSWORD,
clustered: process.env.REDIS_USE_CLUSTERED,
facilityTTL: process.env.REDIS_FACILITY_TTL
}

});
module.exports = nconf;
facilityTTL: process.env.REDIS_FACILITY_TTL,
},
})
module.exports = nconf
Loading