Skip to content

Commit 38a8b77

Browse files
committed
Updating the getResources to be better at catching legacy IDs and not flooding the logs with output
1 parent 9d49d9a commit 38a8b77

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"tc-bus-api-wrapper": "topcoder-platform/tc-bus-api-wrapper.git",
4949
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.6.4",
5050
"uuid": "^3.3.2",
51+
"uuidv4": "^6.2.3",
5152
"winston": "^3.2.1",
5253
"xss": "^1.0.7",
5354
"yamljs": "^0.3.0"

src/services/ResourceService.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const _ = require('lodash')
66
const config = require('config')
77
const Joi = require('joi')
88
const uuid = require('uuid/v4')
9-
// const { validate: uuidValidate } = require('uuid')
9+
const uuidV4 = require('uuidv4')
1010
const moment = require('moment')
1111
const helper = require('../common/helper')
1212
const logger = require('../common/logger')
@@ -45,11 +45,15 @@ async function checkAccess (currentUser, resources) {
4545
* @returns {Array} the search result
4646
*/
4747
async function getResources (currentUser, challengeId, roleId, page, perPage) {
48-
// if (!uuidValidate(challengeId)) {
49-
// throw new errors.BadRequestError(`Challenge ID ${challengeId} must be a valid UUID`)
50-
// }
51-
// Verify that the challenge exists
52-
await helper.getRequest(`${config.CHALLENGE_API_URL}/${challengeId}`)
48+
if (!uuidV4.isUuid(challengeId)) {
49+
throw new errors.BadRequestError(`Challenge ID ${challengeId} must be a valid v5 Challenge Id (UUID)`)
50+
}
51+
try {
52+
// Verify that the challenge exists
53+
await helper.getRequest(`${config.CHALLENGE_API_URL}/${challengeId}`)
54+
} catch (e) {
55+
throw new errors.NotFoundError(`Challenge ID ${challengeId} not found`)
56+
}
5357

5458
const boolQuery = []
5559
const mustQuery = []

0 commit comments

Comments
 (0)