Skip to content

Commit bd9fb3f

Browse files
Add endpoint to fetch user's challenges
1 parent 9a7f04e commit bd9fb3f

20 files changed

+1637
-1799
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ The following parameters can be set in config files or in env variables:
3737
- ES.ES_INDEX: Elasticsearch index name
3838
- ES.ES_TYPE: Elasticsearch index type
3939
- FILE_UPLOAD_SIZE_LIMIT: the file upload size limit in bytes
40-
- CHALLENGES_API_URL: TC challenges API base URL
40+
- RESOURCES_API_URL: TC resources API base URL
4141
- GROUPS_API_URL: TC groups API base URL
42+
- PROJECTS_API_URL: TC projects API base URL
4243
- COPILOT_RESOURCE_ROLE_IDS: copilot resource role ids allowed to upload attachment
4344
- HEALTH_CHECK_TIMEOUT: health check timeout in milliseconds
4445
- SCOPES: the configurable M2M token scopes, refer `config/default.js` for more details
@@ -73,6 +74,7 @@ Go to https://console.aws.amazon.com/ and login. Choose S3 from Service folder a
7374

7475
## Mock api
7576
For postman verification, please use the mock api under mock-api folder. It provides mock endpoint to fetch challenge resources and groups.
77+
You need to ensure DynamoDB configuration in `mock-api/config/default.js` is consistent with `config/default.js`
7678
Go to `mock-api` folder and run command `npm run start` to start the mock-api listening on port 4000
7779

7880
## Create Tables
@@ -87,6 +89,7 @@ Go to `mock-api` folder and run command `npm run start` to start the mock-api li
8789
4. Initialize/Clear database in default environment: `npm run init-db`
8890
5. View table data in default environment: `npm run view-data <ModelName>`, ModelName can be `Challenge`, `ChallengeType`, `ChallengeSetting`, `AuditLog`, `Phase`, `TimelineTemplate`or `Attachment`
8991
6. Create Elasticsearch index: `npm run init-db`, or to re-create index: `npm run init-db force`
92+
7. Synchronize ES data and DynamoDB data: `npm run sync-es`
9093

9194
### Notes
9295
- The seed data are located in `src/scripts/seed`
@@ -106,8 +109,9 @@ Go to `mock-api` folder and run command `npm run start` to start the mock-api li
106109

107110
## Running tests
108111

109-
Before running tests, DynamoDB tables should be created, ES index should be initialized, mock API should be started and
110-
various config parameters are properly set.
112+
Before running tests, AWS S3 bucket should be created, DynamoDB tables should be created, ES index should be initialized, mock API should be started and various config parameters are properly set.
113+
Important notes: You need to ensure DynamoDB configuration in `mock-api/config/default.js` is consistent with `config/default.js`
114+
111115
Seeding db data is not needed.
112116

113117
### Running unit tests

Verification.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# TopCoder Challenge API Verification
22

33
## Postman tests
4+
- clear the environment, run command `npm run init-db` and `npm run init-es force`
45
- import Postman collection and environment in the docs folder to Postman
56
- run tests from up to down in order
7+
- You need to run command `npm run sync-es` before you run `Challenges/get challenge` and `Challenges/search challenge` test case.
68

79
## DynamoDB Verification
810
Run command `npm run view-data <ModelName>` to view table data, ModelName can be `Challenge`, `ChallengeType`, `ChallengeSetting`, `AuditLog`, `Phase`, `TimelineTemplate`or `Attachment`

app-routes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ module.exports = (app) => {
5959
if (def.access && !helper.checkIfExists(def.access, req.authUser.roles)) {
6060
next(new errors.ForbiddenError('You are not allowed to perform this action!'))
6161
} else {
62+
// user token is used in create/update challenge to ensure user can create/update challenge under specific project
63+
req.userToken = req.headers.authorization.split(' ')[1]
6264
next()
6365
}
6466
} else {

app.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ require('./app-routes')(app)
5858
app.use((err, req, res, next) => {
5959
logger.logFullError(err, req.signature || `${req.method} ${req.url}`)
6060
const errorResponse = {}
61-
const status = err.isJoi ? HttpStatus.BAD_REQUEST : (err.httpStatus || HttpStatus.INTERNAL_SERVER_ERROR)
61+
const status = err.isJoi ? HttpStatus.BAD_REQUEST : (err.httpStatus || _.get(err, 'response.status') || HttpStatus.INTERNAL_SERVER_ERROR)
6262

6363
if (_.isArray(err.details)) {
6464
if (err.isJoi) {
@@ -73,6 +73,11 @@ app.use((err, req, res, next) => {
7373
})
7474
}
7575
}
76+
if (_.get(err, 'response.status')) {
77+
// extra error message from axios http response(v4 and v5 tc api)
78+
errorResponse.message = _.get(err, 'response.data.result.content.message') || _.get(err, 'response.data.message')
79+
}
80+
7681
if (_.isUndefined(errorResponse.message)) {
7782
if (err.message && status !== HttpStatus.INTERNAL_SERVER_ERROR) {
7883
errorResponse.message = err.message

config/default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ module.exports = {
4141
// in bytes
4242
FILE_UPLOAD_SIZE_LIMIT: process.env.FILE_UPLOAD_SIZE_LIMIT
4343
? Number(process.env.FILE_UPLOAD_SIZE_LIMIT) : 50 * 1024 * 1024, // 50M
44-
CHALLENGES_API_URL: process.env.CHALLENGES_API_URL || 'http://localhost:4000/v5/challenges',
44+
RESOURCES_API_URL: process.env.RESOURCES_API_URL || 'http://localhost:4000/v5/resources',
4545
GROUPS_API_URL: process.env.GROUPS_API_URL || 'http://localhost:4000/v5/groups',
46+
PROJECTS_API_URL: process.env.PROJECTS_API_URL || 'http://localhost:4000/v4/projects',
4647
// copilot resource role ids allowed to upload attachment
4748
COPILOT_RESOURCE_ROLE_IDS: process.env.COPILOT_RESOURCE_ROLE_IDS
4849
? process.env.COPILOT_RESOURCE_ROLE_IDS.split(',') : ['10ba038e-48da-487b-96e8-8d3b99b6d18b'],

docs/swagger.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ paths:
156156
description: Filter by 'updatedBy' field, case-insensitive, partial matches are allowed.
157157
required: false
158158
type: string
159+
- name: memberId
160+
in: query
161+
description: Filter by member, only return challenges this member can access to
162+
required: false
163+
type: string
159164
responses:
160165
'200':
161166
description: OK

0 commit comments

Comments
 (0)