Skip to content

Commit db142a8

Browse files
Merge branch 'develop' into develop
2 parents a671b72 + 70c4c14 commit db142a8

14 files changed

+228
-57
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ aws dynamodb scan --table-name TimelineTemplate --endpoint-url http://localhost:
8080
aws dynamodb scan --table-name Attachment --endpoint-url http://localhost:7777
8181
```
8282

83+
## Scripts
84+
1. Drop/delete tables: `npm run drop-tables`
85+
2. Creating tables: `npm run create-tables`
86+
3. Seed/Insert data to tables: `npm run seed-tables`
87+
88+
### Notes
89+
- The seed data are located in `src/scripts/seed`
90+
8391
## Local Deployment
8492

8593
- Install dependencies `npm install`

app-constants.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,9 @@ const UserRoles = {
77
}
88

99
const prizeSetTypes = {
10-
Code: 'Code',
11-
F2F: 'First to Finish',
12-
CheckPoint: 'Check Point',
13-
MM: 'Marathon'
14-
}
15-
16-
const prizeTypes = {
17-
First: 'first place',
18-
Second: 'second place',
19-
Third: 'third place',
20-
Fouth: 'fourth place',
21-
Fifth: 'fifth place'
10+
ChallengePrizes: 'Challenge prizes',
11+
CopilotPayment: 'Copilot payment',
12+
ReviewerPayment: 'Reviewer payment'
2213
}
2314

2415
const challengeStatuses = {
@@ -51,7 +42,6 @@ const Topics = {
5142
module.exports = {
5243
UserRoles,
5344
prizeSetTypes,
54-
prizeTypes,
5545
challengeStatuses,
5646
EVENT_ORIGINATOR,
5747
EVENT_MIME_TYPE,

docs/swagger.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,9 +1657,6 @@ definitions:
16571657
reviewType:
16581658
type: string
16591659
description: the review type
1660-
markdown:
1661-
type: boolean
1662-
description: the mark down flag
16631660
tags:
16641661
type: array
16651662
items:
@@ -1707,7 +1704,6 @@ definitions:
17071704
- created
17081705
- createdBy
17091706
- reviewType
1710-
- markdown
17111707
- tags
17121708
- projectId
17131709
- forumId
@@ -1866,9 +1862,6 @@ definitions:
18661862
reviewType:
18671863
type: string
18681864
description: the review type
1869-
markdown:
1870-
type: boolean
1871-
description: the mark down flag
18721865
tags:
18731866
type: array
18741867
items:
@@ -1900,7 +1893,6 @@ definitions:
19001893
- phases
19011894
- prizeSets
19021895
- reviewType
1903-
- markdown
19041896
- tags
19051897
- projectId
19061898
- forumId
@@ -1962,9 +1954,6 @@ definitions:
19621954
reviewType:
19631955
type: string
19641956
description: the review type
1965-
markdown:
1966-
type: boolean
1967-
description: the mark down flag
19681957
tags:
19691958
type: array
19701959
items:
@@ -2013,7 +2002,6 @@ definitions:
20132002
- created
20142003
- createdBy
20152004
- reviewType
2016-
- markdown
20172005
- tags
20182006
- projectId
20192007
- forumId

docs/topcoder-challenge-api.postman_collection.json

Lines changed: 20 additions & 20 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
"start": "node app.js",
88
"lint": "standard",
99
"lint:fix": "standard --fix",
10-
"init-db": "node src/init-db.js"
10+
"init-db": "node src/init-db.js",
11+
"drop-tables": "node src/scripts/drop-tables.js",
12+
"create-tables": "node src/scripts/create-tables.js",
13+
"seed-tables": "node src/scripts/seed-tables.js"
1114
},
1215
"author": "TCSCODER",
1316
"license": "none",

src/models/Challenge.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ const schema = new Schema({
5252
type: String,
5353
required: true
5454
},
55-
markdown: {
56-
type: Boolean,
57-
required: true
58-
},
5955
// tag names
6056
tags: {
6157
type: Array,

src/scripts/create-tables.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Create table schemes in database
3+
*/
4+
5+
const models = require('../models')
6+
const logger = require('../common/logger')
7+
8+
logger.info('Requesting to create tables...')
9+
10+
const promises = []
11+
12+
Object.keys(models).forEach(modelName => {
13+
promises.push(models[modelName].$__.table.create())
14+
})
15+
16+
Promise.all(promises)
17+
.then(() => {
18+
logger.info('All tables have been requested to be created. Creating processes is run asynchronously')
19+
process.exit()
20+
})
21+
.catch((err) => {
22+
logger.logFullError(err)
23+
process.exit(1)
24+
})

src/scripts/drop-tables.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Drop tables in database. All data will be cleared.
3+
*/
4+
5+
const models = require('../models')
6+
const logger = require('../common/logger')
7+
8+
logger.info('Requesting to delete tables...')
9+
10+
const promises = []
11+
12+
Object.keys(models).forEach(modelName => {
13+
promises.push(models[modelName].$__.table.delete())
14+
})
15+
16+
Promise.all(promises)
17+
.then(() => {
18+
logger.info('All tables have been requested to be deleted. Deleting processes is run asynchronously')
19+
process.exit()
20+
})
21+
.catch((err) => {
22+
logger.logFullError(err)
23+
process.exit(1)
24+
})

src/scripts/seed-tables.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Insert seed data to tables in database
3+
*/
4+
5+
const { get } = require('lodash')
6+
const models = require('../models')
7+
const logger = require('../common/logger')
8+
9+
logger.info('Requesting to insert seed data to the tables...')
10+
11+
const promises = []
12+
13+
Object.keys(models).forEach(modelName => {
14+
try {
15+
const data = require(`./seed/${modelName}.json`)
16+
logger.info(`Inserting ${get(data, 'length')} records in table ${modelName}`)
17+
promises.push(models[modelName].batchPut(data))
18+
} catch (e) {
19+
logger.warn(`No records will be inserted in table ${modelName}`)
20+
}
21+
})
22+
23+
Promise.all(promises)
24+
.then(() => {
25+
logger.info('All tables have been inserted with the data. The processes is run asynchronously')
26+
process.exit()
27+
})
28+
.catch((err) => {
29+
logger.logFullError(err)
30+
process.exit(1)
31+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"id": "2d88c598-70f0-4054-8a45-7da38d0ca424",
4+
"name": "Multiple submissions allowed"
5+
},
6+
{
7+
"id": "57ba5343-2269-4cd0-b3a0-8771da94f1fc",
8+
"name": "Stock icons allowed"
9+
}
10+
]

src/scripts/seed/ChallengeType.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"id": "45415132-79fa-4d13-a9ac-71f50020dc10",
4+
"name": "Code",
5+
"description": "Code",
6+
"isActive": true
7+
},
8+
{
9+
"id": "6950164f-3c5e-4bdc-abc8-22aaf5a1bd49",
10+
"name": "F2F",
11+
"description": "First 2 Finish",
12+
"isActive": true
13+
},
14+
{
15+
"id": "a93544bc-c165-4af4-b55e-18f3593b457a",
16+
"name": "Bug Hunt",
17+
"description": "Bug Hunt",
18+
"isActive": true
19+
}
20+
]

src/scripts/seed/Phase.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[
2+
{
3+
"id": "a93544bc-c165-4af4-b55e-18f3593b457a",
4+
"name": "Registration",
5+
"description": "Registration Phase",
6+
"isActive": true,
7+
"duration": 72
8+
},
9+
{
10+
"id": "6950164f-3c5e-4bdc-abc8-22aaf5a1bd49",
11+
"name": "Submission",
12+
"description": "Submission Phase",
13+
"predecessor": "a93544bc-c165-4af4-b55e-18f3593b457a",
14+
"isActive": true,
15+
"duration": 72
16+
},
17+
{
18+
"id": "aa5a3f78-79e0-4bf7-93ff-b11e8f5b398b",
19+
"name": "Review",
20+
"description": "Review Phase",
21+
"predecessor": "6950164f-3c5e-4bdc-abc8-22aaf5a1bd49",
22+
"isActive": true,
23+
"duration": 48
24+
},
25+
{
26+
"id": "1c24cfb3-5b0a-4dbd-b6bd-4b0dff5349c6",
27+
"name": "Appeals",
28+
"description": "Appeals Phase",
29+
"predecessor": "aa5a3f78-79e0-4bf7-93ff-b11e8f5b398b",
30+
"isActive": true,
31+
"duration": 24
32+
},
33+
{
34+
"id": "797a6af7-cd3f-4436-9fca-9679f773bee9",
35+
"name": "Appeals Response",
36+
"description": "Appeals Response Phase",
37+
"predecessor": "1c24cfb3-5b0a-4dbd-b6bd-4b0dff5349c6",
38+
"isActive": true,
39+
"duration": 24
40+
},
41+
{
42+
"id": "3e2afca6-9542-4763-a135-96b33f12c082",
43+
"name": "Final Fixes",
44+
"description": "Final Fixes Phase",
45+
"predecessor": "797a6af7-cd3f-4436-9fca-9679f773bee9",
46+
"isActive": true,
47+
"duration": 24
48+
},
49+
{
50+
"id": "ad985cff-ad3e-44de-b54e-3992505ba0ae",
51+
"name": "Approval",
52+
"description": "Approval Phase",
53+
"predecessor": "3e2afca6-9542-4763-a135-96b33f12c082",
54+
"isActive": true,
55+
"duration": 24
56+
}
57+
]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[
2+
{
3+
"id": "a93544bc-c165-4af4-b55e-18f3593b457a",
4+
"name": "Standard Code",
5+
"description": "Standard Code challenge timeline",
6+
"isActive": true,
7+
"phases": ["Registration","Submission", "Review", "Appeals", "Appeals Response"]
8+
},
9+
{
10+
"id": "592b0e63-5503-4d21-bb79-54202ff03135",
11+
"name": "Code with final fixes",
12+
"description": "Code challenge with final fixe phase",
13+
"isActive": true,
14+
"phases": ["Registration","Submission", "Review", "Appeals", "Appeals Response", "Final Fixes", "Approval"]
15+
},
16+
{
17+
"id": "acf94fff-8e26-4617-b96c-61a46561623a",
18+
"name": "Idea/report generation",
19+
"description": "Idea/report generation",
20+
"isActive": true,
21+
"phases": ["Registration","Submission", "Review"]
22+
}
23+
]

src/services/ChallengeService.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async function filterChallengesByGroupsAccess (currentUser, challenges) {
4545
async function ensureAccessibleByGroupsAccess (currentUser, challenge) {
4646
const filtered = await filterChallengesByGroupsAccess(currentUser, [challenge])
4747
if (filtered.length === 0) {
48-
throw new errors.ForbiddenError('You are not allowed to access the challenge.')
48+
throw new errors.ForbiddenError(`You don't have access to this group!`)
4949
}
5050
}
5151

@@ -180,12 +180,11 @@ createChallenge.schema = {
180180
description: Joi.string(),
181181
prizes: Joi.array().items(Joi.object().keys({
182182
description: Joi.string(),
183-
type: Joi.string().valid(_.values(constants.prizeTypes)).required(),
183+
type: Joi.string().required(),
184184
value: Joi.number().positive().required()
185185
})).min(1).required()
186186
})).min(1).required(),
187187
reviewType: Joi.string().required(),
188-
markdown: Joi.boolean().required(),
189188
tags: Joi.array().items(Joi.string().required()).min(1).required(), // tag names
190189
projectId: Joi.number().integer().positive().required(),
191190
forumId: Joi.number().integer().positive().required(),
@@ -546,12 +545,11 @@ fullyUpdateChallenge.schema = {
546545
description: Joi.string(),
547546
prizes: Joi.array().items(Joi.object().keys({
548547
description: Joi.string(),
549-
type: Joi.string().valid(_.values(constants.prizeTypes)).required(),
548+
type: Joi.string().required(),
550549
value: Joi.number().positive().required()
551550
})).min(1).required()
552551
})).min(1).required(),
553552
reviewType: Joi.string().required(),
554-
markdown: Joi.boolean().required(),
555553
tags: Joi.array().items(Joi.string().required()).min(1).required(), // tag names
556554
projectId: Joi.number().integer().positive().required(),
557555
forumId: Joi.number().integer().positive().required(),
@@ -598,12 +596,11 @@ partiallyUpdateChallenge.schema = {
598596
description: Joi.string(),
599597
prizes: Joi.array().items(Joi.object().keys({
600598
description: Joi.string(),
601-
type: Joi.string().valid(_.values(constants.prizeTypes)).required(),
599+
type: Joi.string().required(),
602600
value: Joi.number().positive().required()
603601
})).min(1).required()
604602
})).min(1),
605603
reviewType: Joi.string(),
606-
markdown: Joi.boolean(),
607604
tags: Joi.array().items(Joi.string().required()).min(1), // tag names
608605
projectId: Joi.number().integer().positive(),
609606
forumId: Joi.number().integer().positive(),

0 commit comments

Comments
 (0)