Skip to content

Commit 0127ab3

Browse files
Merge pull request #22 from topcoder-platform/add-user-challenges-endpoint
Add endpoint to fetch user's challenges
2 parents bcf68c7 + a456cd0 commit 0127ab3

19 files changed

+1626
-1788
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ The following parameters can be set in config files or in env variables:
3838
- ES.ES_TYPE: Elasticsearch index type
3939
- ES.ES_REFRESH: Elasticsearch refresh method. Default to string `true`(i.e. refresh immediately)
4040
- FILE_UPLOAD_SIZE_LIMIT: the file upload size limit in bytes
41-
- CHALLENGES_API_URL: TC challenges API base URL
41+
- RESOURCES_API_URL: TC resources API base URL
4242
- GROUPS_API_URL: TC groups API base URL
43+
- PROJECTS_API_URL: TC projects API base URL
4344
- COPILOT_RESOURCE_ROLE_IDS: copilot resource role ids allowed to upload attachment
4445
- HEALTH_CHECK_TIMEOUT: health check timeout in milliseconds
4546
- SCOPES: the configurable M2M token scopes, refer `config/default.js` for more details
@@ -76,6 +77,7 @@ It starts Elasticsearch, DynamoDB and S3 compatible server.
7677

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

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

9497
### Notes
9598
- The seed data are located in `src/scripts/seed`
@@ -115,6 +118,7 @@ Go to `mock-api` folder and run command `npm run start` to start the mock-api li
115118
- Create DynamoDB tables.
116119
- Initialize ES index.
117120
- Various config parameters should be properly set.
121+
118122
Seeding db data is not needed.
119123

120124
### 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
@@ -42,8 +42,9 @@ module.exports = {
4242
// in bytes
4343
FILE_UPLOAD_SIZE_LIMIT: process.env.FILE_UPLOAD_SIZE_LIMIT
4444
? Number(process.env.FILE_UPLOAD_SIZE_LIMIT) : 50 * 1024 * 1024, // 50M
45-
CHALLENGES_API_URL: process.env.CHALLENGES_API_URL || 'http://localhost:4000/v5/challenges',
45+
RESOURCES_API_URL: process.env.RESOURCES_API_URL || 'http://localhost:4000/v5/resources',
4646
GROUPS_API_URL: process.env.GROUPS_API_URL || 'http://localhost:4000/v5/groups',
47+
PROJECTS_API_URL: process.env.PROJECTS_API_URL || 'http://localhost:4000/v4/projects',
4748
// copilot resource role ids allowed to upload attachment
4849
COPILOT_RESOURCE_ROLE_IDS: process.env.COPILOT_RESOURCE_ROLE_IDS
4950
? 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)