@@ -6,8 +6,10 @@ const cache = require('memory-cache');
6
6
const { PROGRAM_YEAR_STATUS_CODES , ORGANIZATION_PROVIDER_TYPES , CHANGE_REQUEST_TYPES } = require ( '../util/constants' ) ;
7
7
const { ProgramYearMappings, SystemMessagesMappings } = require ( '../util/mapping/Mappings' ) ;
8
8
const { MappableObjectForFront } = require ( '../util/mapping/MappableObject' ) ;
9
+ const log = require ( './logger' ) ;
9
10
10
11
const lookupCache = new cache . Cache ( ) ;
12
+ const ONE_HOUR_MS = 60 * 60 * 1000 ; // Cache timeout set for one hour
11
13
12
14
const organizationType = [
13
15
{
@@ -75,7 +77,7 @@ async function getLicenseCategory() {
75
77
. sort ( ( a , b ) => {
76
78
return a . ccof_categorynumber - b . ccof_categorynumber ;
77
79
} ) ;
78
- lookupCache . put ( 'licenseCategory' , resData , 60 * 60 * 1000 ) ;
80
+ lookupCache . put ( 'licenseCategory' , resData , ONE_HOUR_MS ) ;
79
81
}
80
82
return resData ;
81
83
}
@@ -137,7 +139,7 @@ async function getLookupInfo(req, res) {
137
139
return _ . pick ( item , [ 'ccof_childcarecategorynumber' , 'ccof_name' , 'ccof_description' , 'ccof_childcare_categoryid' ] ) ;
138
140
} ) ;
139
141
140
- const licenseCategory = await getLicenseCategory ( ) ;
142
+ const [ licenseCategory , healthAuthorities ] = await Promise . all ( [ getLicenseCategory ( ) , getGlobalOptionsData ( 'ccof_healthauthority' ) ] ) ;
141
143
resData = {
142
144
programYear : programYears ,
143
145
childCareCategory : childCareCategory ,
@@ -146,8 +148,9 @@ async function getLookupInfo(req, res) {
146
148
groupLicenseCategory : licenseCategory . groupLicenseCategory ,
147
149
familyLicenseCategory : licenseCategory . familyLicenseCategory ,
148
150
'changeRequestTypes:' : CHANGE_REQUEST_TYPES ,
151
+ healthAuthorities : healthAuthorities ,
149
152
} ;
150
- lookupCache . put ( 'lookups' , resData , 60 * 60 * 1000 ) ;
153
+ lookupCache . put ( 'lookups' , resData , ONE_HOUR_MS ) ;
151
154
}
152
155
return res . status ( HttpStatus . OK ) . json ( resData ) ;
153
156
}
@@ -159,11 +162,25 @@ async function getSystemMessages(req, res) {
159
162
systemMessages = [ ] ;
160
163
const resData = await getOperation ( `ccof_systemmessages?$filter=(ccof_startdate le ${ currentTime } and ccof_enddate ge ${ currentTime } )` ) ;
161
164
resData ?. value . forEach ( ( message ) => systemMessages . push ( new MappableObjectForFront ( message , SystemMessagesMappings ) . data ) ) ;
162
- lookupCache . put ( 'systemMessages' , systemMessages , 60 * 60 * 1000 ) ;
165
+ lookupCache . put ( 'systemMessages' , systemMessages , ONE_HOUR_MS ) ;
163
166
}
164
167
return res . status ( HttpStatus . OK ) . json ( systemMessages ) ;
165
168
}
166
169
170
+ async function getGlobalOptionsData ( operationName ) {
171
+ try {
172
+ const response = await getOperation ( `GlobalOptionSetDefinitions(Name='${ operationName } ')` ) ;
173
+ const data =
174
+ response ?. Options ?. map ( ( item ) => ( {
175
+ id : Number ( item . Value ) ,
176
+ description : item . Label ?. LocalizedLabels ?. [ 0 ] ?. Label ?? null ,
177
+ } ) ) || [ ] ;
178
+ return data ;
179
+ } catch ( error ) {
180
+ log . error ( `Error getting global options data for ${ operationName } :` , error ) ;
181
+ }
182
+ }
183
+
167
184
module . exports = {
168
185
getLookupInfo,
169
186
getLicenseCategory,
0 commit comments