@@ -15,7 +15,7 @@ const m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_
1515const axios = require ( 'axios' )
1616const busApi = require ( 'topcoder-bus-api-wrapper' )
1717const elasticsearch = require ( 'elasticsearch' )
18- const moment = require ( 'moment ' )
18+ const NodeCache = require ( 'node-cache ' )
1919const HttpStatus = require ( 'http-status-codes' )
2020const xss = require ( 'xss' )
2121const logger = require ( './logger' )
@@ -48,6 +48,9 @@ function wrapExpress (fn) {
4848 }
4949}
5050
51+ // Internal cache
52+ const internalCache = new NodeCache ( { stdTTL : config . INTERNAL_CACHE_TTL } )
53+
5154/**
5255 * Wrap all functions from object
5356 * @param obj the object (controller exports)
@@ -447,7 +450,7 @@ async function createResource (challengeId, memberHandle, roleId) {
447450 * @param {String } description The description
448451 * @param {String } type The type
449452 * @param {String } token The token
450- * @returns
453+ * @returns
451454 */
452455async function createSelfServiceProject ( name , description , type , token ) {
453456 const projectObj = {
@@ -456,15 +459,15 @@ async function createSelfServiceProject (name, description, type, token) {
456459 type
457460 }
458461 const url = `${ config . PROJECTS_API_URL } `
459- const res = await axios . post ( url , projectObj , { headers : { Authorization : `Bearer ${ token } ` } } )
462+ const res = await axios . post ( url , projectObj , { headers : { Authorization : `Bearer ${ token } ` } } )
460463 return _ . get ( res , 'data.id' )
461464}
462465
463466/**
464467 * Get project payment
465468 * @param {String } projectId the project id
466469 */
467- async function getProjectPayment ( projectId ) {
470+ async function getProjectPayment ( projectId ) {
468471 const token = await getM2MToken ( )
469472 const url = `${ config . CUSTOMER_PAYMENTS_URL } `
470473 const res = await axios . get ( url , {
@@ -473,7 +476,7 @@ async function createSelfServiceProject (name, description, type, token) {
473476 referenceId : projectId ,
474477 reference : 'project'
475478 }
476- } )
479+ } )
477480 const [ payment ] = res . data
478481 return payment
479482}
@@ -514,7 +517,7 @@ async function cancelPayment (paymentId) {
514517 * @param {String } cancelReason the cancel reasonn
515518 * @param {Object } currentUser the current user
516519 */
517- async function cancelProject ( projectId , cancelReason , currentUser ) {
520+ async function cancelProject ( projectId , cancelReason , currentUser ) {
518521 let payment = await getProjectPayment ( projectId )
519522 const project = await ensureProjectExist ( projectId , currentUser )
520523 if ( project . status === 'cancelled' ) return // already canceled
@@ -998,7 +1001,7 @@ async function validateChallengeTerms (terms = []) {
9981001async function _filterChallengesByGroupsAccess ( currentUser , challenges ) {
9991002 const res = [ ]
10001003 const needToCheckForGroupAccess = ! currentUser ? true : ! currentUser . isMachine && ! hasAdminRole ( currentUser )
1001- if ( ! needToCheckForGroupAccess ) return challenges
1004+ if ( ! needToCheckForGroupAccess ) return challenges
10021005
10031006 let userGroups
10041007
@@ -1234,6 +1237,14 @@ async function submitZendeskRequest (request) {
12341237 }
12351238}
12361239
1240+ function getFromInternalCache ( key ) {
1241+ return internalCache . get ( key )
1242+ }
1243+
1244+ function setToInternalCache ( key , value ) {
1245+ internalCache . set ( key , value )
1246+ }
1247+
12371248module . exports = {
12381249 wrapExpress,
12391250 autoWrapExpress,
@@ -1287,5 +1298,7 @@ module.exports = {
12871298 sendSelfServiceNotification,
12881299 getMemberByHandle,
12891300 submitZendeskRequest,
1290- updateSelfServiceProjectInfo
1301+ updateSelfServiceProjectInfo,
1302+ getFromInternalCache,
1303+ setToInternalCache
12911304}
0 commit comments