@@ -15,7 +15,7 @@ const m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_
15
15
const axios = require ( 'axios' )
16
16
const busApi = require ( 'topcoder-bus-api-wrapper' )
17
17
const elasticsearch = require ( 'elasticsearch' )
18
- const moment = require ( 'moment ' )
18
+ const NodeCache = require ( 'node-cache ' )
19
19
const HttpStatus = require ( 'http-status-codes' )
20
20
const xss = require ( 'xss' )
21
21
const logger = require ( './logger' )
@@ -48,6 +48,9 @@ function wrapExpress (fn) {
48
48
}
49
49
}
50
50
51
+ // Internal cache
52
+ const internalCache = new NodeCache ( { stdTTL : config . INTERNAL_CACHE_TTL } )
53
+
51
54
/**
52
55
* Wrap all functions from object
53
56
* @param obj the object (controller exports)
@@ -447,7 +450,7 @@ async function createResource (challengeId, memberHandle, roleId) {
447
450
* @param {String } description The description
448
451
* @param {String } type The type
449
452
* @param {String } token The token
450
- * @returns
453
+ * @returns
451
454
*/
452
455
async function createSelfServiceProject ( name , description , type , token ) {
453
456
const projectObj = {
@@ -456,15 +459,15 @@ async function createSelfServiceProject (name, description, type, token) {
456
459
type
457
460
}
458
461
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 } ` } } )
460
463
return _ . get ( res , 'data.id' )
461
464
}
462
465
463
466
/**
464
467
* Get project payment
465
468
* @param {String } projectId the project id
466
469
*/
467
- async function getProjectPayment ( projectId ) {
470
+ async function getProjectPayment ( projectId ) {
468
471
const token = await getM2MToken ( )
469
472
const url = `${ config . CUSTOMER_PAYMENTS_URL } `
470
473
const res = await axios . get ( url , {
@@ -473,7 +476,7 @@ async function createSelfServiceProject (name, description, type, token) {
473
476
referenceId : projectId ,
474
477
reference : 'project'
475
478
}
476
- } )
479
+ } )
477
480
const [ payment ] = res . data
478
481
return payment
479
482
}
@@ -514,7 +517,7 @@ async function cancelPayment (paymentId) {
514
517
* @param {String } cancelReason the cancel reasonn
515
518
* @param {Object } currentUser the current user
516
519
*/
517
- async function cancelProject ( projectId , cancelReason , currentUser ) {
520
+ async function cancelProject ( projectId , cancelReason , currentUser ) {
518
521
let payment = await getProjectPayment ( projectId )
519
522
const project = await ensureProjectExist ( projectId , currentUser )
520
523
if ( project . status === 'cancelled' ) return // already canceled
@@ -998,7 +1001,7 @@ async function validateChallengeTerms (terms = []) {
998
1001
async function _filterChallengesByGroupsAccess ( currentUser , challenges ) {
999
1002
const res = [ ]
1000
1003
const needToCheckForGroupAccess = ! currentUser ? true : ! currentUser . isMachine && ! hasAdminRole ( currentUser )
1001
- if ( ! needToCheckForGroupAccess ) return challenges
1004
+ if ( ! needToCheckForGroupAccess ) return challenges
1002
1005
1003
1006
let userGroups
1004
1007
@@ -1234,6 +1237,14 @@ async function submitZendeskRequest (request) {
1234
1237
}
1235
1238
}
1236
1239
1240
+ function getFromInternalCache ( key ) {
1241
+ return internalCache . get ( key )
1242
+ }
1243
+
1244
+ function setToInternalCache ( key , value ) {
1245
+ internalCache . set ( key , value )
1246
+ }
1247
+
1237
1248
module . exports = {
1238
1249
wrapExpress,
1239
1250
autoWrapExpress,
@@ -1287,5 +1298,7 @@ module.exports = {
1287
1298
sendSelfServiceNotification,
1288
1299
getMemberByHandle,
1289
1300
submitZendeskRequest,
1290
- updateSelfServiceProjectInfo
1301
+ updateSelfServiceProjectInfo,
1302
+ getFromInternalCache,
1303
+ setToInternalCache
1291
1304
}
0 commit comments