Skip to content

Commit bcd0607

Browse files
challenge data model updates
1 parent 01cda71 commit bcd0607

18 files changed

+215
-227
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ You can find sample `.env` files inside the `/docs` directory.
7676
2. Creating tables: `npm run create-tables`
7777
3. Seed/Insert data to tables: `npm run seed-tables`
7878
4. Initialize/Clear database in default environment: `npm run init-db`
79-
5. View table data in default environment: `npm run view-data <ModelName>`, ModelName can be `Challenge`, `ChallengeType`, `ChallengeSetting`, `AuditLog`, `Phase`, `TimelineTemplate`or `Attachment`
79+
5. View table data in default environment: `npm run view-data <ModelName>`, ModelName can be `Challenge`, `ChallengeType`, `ChallengeMetadata`, `AuditLog`, `Phase`, `TimelineTemplate`or `Attachment`
8080
6. Create Elasticsearch index: `npm run init-db`, or to re-create index: `npm run init-db force`
8181
7. Synchronize ES data and DynamoDB data: `npm run sync-es`
8282

Verification.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- You need to run command `npm run sync-es` before you run `Challenges/get challenge` and `Challenges/search challenge` test case.
88

99
## DynamoDB Verification
10-
Run command `npm run view-data <ModelName>` to view table data, ModelName can be `Challenge`, `ChallengeType`, `ChallengeSetting`, `AuditLog`, `Phase`, `TimelineTemplate`, `Attachment` or `ChallengeTypeTimelineTemplate`
10+
Run command `npm run view-data <ModelName>` to view table data, ModelName can be `Challenge`, `ChallengeType`, `ChallengeMetadata`, `AuditLog`, `Phase`, `TimelineTemplate`, `Attachment` or `ChallengeTypeTimelineTemplate`
1111

1212
## S3 Verification
1313

app-constants.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ const Topics = {
3030
ChallengeUpdated: 'challenge.notification.update',
3131
ChallengeTypeCreated: 'test.new.bus.events', // 'challenge.action.type.created',
3232
ChallengeTypeUpdated: 'test.new.bus.events', // 'challenge.action.type.updated',
33-
ChallengeSettingCreated: 'test.new.bus.events', // 'challenge.action.setting.created',
34-
ChallengeSettingUpdated: 'test.new.bus.events', // 'challenge.action.setting.updated',
33+
ChallengeMetadataCreated: 'test.new.bus.events', // 'challenge.action.metdata.created',
34+
ChallengeMetadataUpdated: 'test.new.bus.events', // 'challenge.action.metadata.updated',
3535
ChallengePhaseCreated: 'test.new.bus.events', // 'challenge.action.phase.created',
3636
ChallengePhaseUpdated: 'test.new.bus.events', // 'challenge.action.phase.updated',
3737
ChallengePhaseDeleted: 'test.new.bus.events', // 'challenge.action.phase.deleted',

config/default.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ module.exports = {
7575
DELETE: process.env.SCOPE_CHALLENGE_TYPE_TIMELINE_TEMPLATES_DELETE || 'delete:challenge_type_timeline_templates',
7676
ALL: process.env.SCOPE_CHALLENGE_TYPE_TIMELINE_TEMPLATES_ALL || 'all:challenge_type_timeline_templates'
7777
},
78-
CHALLENGE_SETTINGS: {
79-
READ: process.env.SCOPE_CHALLENGE_SETTINGS_READ || 'read:challenge_settings',
80-
CREATE: process.env.SCOPE_CHALLENGE_SETTINGS_CREATE || 'create:challenge_settings',
81-
UPDATE: process.env.SCOPE_CHALLENGE_SETTINGS_UPDATE || 'update:challenge_settings',
82-
ALL: process.env.SCOPE_CHALLENGE_SETTINGS_ALL || 'all:challenge_settings'
78+
CHALLENGE_METADATA: {
79+
READ: process.env.SCOPE_CHALLENGE_METADATA_READ || 'read:challenge_metadata',
80+
CREATE: process.env.SCOPE_CHALLENGE_METADATA_CREATE || 'create:challenge_metadata',
81+
UPDATE: process.env.SCOPE_CHALLENGE_METADATA_UPDATE || 'update:challenge_metadata',
82+
ALL: process.env.SCOPE_CHALLENGE_METADATA_ALL || 'all:challenge_metadata'
8383
},
8484
CHALLENGE_AUDIT_LOGS: {
8585
READ: process.env.SCOPE_CHALLENGE_AUDIT_LOGS_READ || 'read:challenge_audit_logs'

docs/swagger.yaml

Lines changed: 28 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,10 @@ paths:
650650
description: Server error
651651
schema:
652652
$ref: '#/definitions/ErrorModel'
653-
/challenge-settings:
653+
/challenge-metadata:
654654
get:
655655
tags:
656-
- ChallengeSettings
656+
- ChallengeMetadata
657657
description: |
658658
Retrieve challenge settings in the system.
659659
security:
@@ -674,7 +674,7 @@ paths:
674674
schema:
675675
type: array
676676
items:
677-
$ref: '#/definitions/ChallengeSettings'
677+
$ref: '#/definitions/ChallengeMetadata'
678678
headers:
679679
X-Next-Page:
680680
type: integer
@@ -717,7 +717,7 @@ paths:
717717
$ref: '#/definitions/ErrorModel'
718718
post:
719719
tags:
720-
- ChallengeSettings
720+
- ChallengeChallengeMetadataSettings
721721
description: |
722722
Create a new challenge setting in the system.
723723
security:
@@ -729,12 +729,12 @@ paths:
729729
name: body
730730
required: true
731731
schema:
732-
$ref: '#/definitions/ChallengeSettingsData'
732+
$ref: '#/definitions/ChallengeMetadataData'
733733
responses:
734734
'201':
735735
description: Created - The request was successful and the resource is returned.
736736
schema:
737-
$ref: '#/definitions/ChallengeSettings'
737+
$ref: '#/definitions/ChallengeMetadata'
738738
'400':
739739
description: Bad request. Request parameters were invalid.
740740
schema:
@@ -758,17 +758,17 @@ paths:
758758
description: Server error
759759
schema:
760760
$ref: '#/definitions/ErrorModel'
761-
'/challenge-settings/:challengeSettingId':
761+
'/challenge-metadata/:challengeMetadataId':
762762
get:
763763
tags:
764-
- ChallengeSettings
764+
- ChallengeMetadata
765765
description: Retrieve the Challenge settings with provided challenge settings id.
766766
security:
767767
- bearer: []
768768
produces:
769769
- application/json
770770
parameters:
771-
- name: challengeSettingId
771+
- name: challengeMetadataId
772772
in: path
773773
required: true
774774
type: string
@@ -778,7 +778,7 @@ paths:
778778
'200':
779779
description: OK
780780
schema:
781-
$ref: '#/definitions/ChallengeSettings'
781+
$ref: '#/definitions/ChallengeMetadata'
782782
'400':
783783
description: Bad request. Request parameters were invalid.
784784
schema:
@@ -803,29 +803,29 @@ paths:
803803
$ref: '#/definitions/ErrorModel'
804804
put:
805805
tags:
806-
- ChallengeSettings
806+
- ChallengeMetadata
807807
description: Update the challenge settings with the specified id.
808808
security:
809809
- bearer: []
810810
produces:
811811
- application/json
812812
parameters:
813-
- name: challengeSettingId
813+
- name: challengeMetadataId
814814
in: path
815815
required: true
816816
type: string
817817
format: UUID
818-
description: The id of challengeSettings to update
818+
description: The id of ChallengeMetadata to update
819819
- in: body
820820
name: body
821821
required: true
822822
schema:
823-
$ref: '#/definitions/ChallengeSettingsData'
823+
$ref: '#/definitions/ChallengeMetadataData'
824824
responses:
825825
'200':
826826
description: Updated - The request was successful and the resource is returned.
827827
schema:
828-
$ref: '#/definitions/ChallengeSettings'
828+
$ref: '#/definitions/ChallengeMetadata'
829829
'400':
830830
description: Bad request. Request parameters were invalid.
831831
schema:
@@ -1915,7 +1915,7 @@ definitions:
19151915
- $ref: '#/definitions/ChallengeTypeData'
19161916
required:
19171917
- id
1918-
ChallengeSettings:
1918+
ChallengeMetadata:
19191919
type: object
19201920
allOf:
19211921
- type: object
@@ -1924,7 +1924,7 @@ definitions:
19241924
type: string
19251925
description: The challenge settings id.
19261926
format: UUID
1927-
- $ref: '#/definitions/ChallengeSettingsData'
1927+
- $ref: '#/definitions/ChallengeMetadataData'
19281928
required:
19291929
- id
19301930
Phase:
@@ -1982,7 +1982,7 @@ definitions:
19821982
privateDescription:
19831983
type: string
19841984
description: returned only if the user is registered on the challenge.
1985-
challengeSettings:
1985+
ChallengeMetadata:
19861986
type: array
19871987
items:
19881988
properties:
@@ -2068,22 +2068,8 @@ definitions:
20682068
terms:
20692069
type: array
20702070
items:
2071-
properties:
2072-
id:
2073-
type: integer
2074-
description: The terms of use id
2075-
agreeabilityType:
2076-
type: string
2077-
description: the terms of use agreeability type
2078-
title:
2079-
type: string
2080-
description: the terms of use title
2081-
url:
2082-
type: string
2083-
description: the terms of use url
2084-
templateId:
2085-
type: string
2086-
description: the template id of the terms of use (only valid when the terms agreeability type is 'Docusignable')
2071+
type: string
2072+
description: The terms of use id
20872073
numOfSubmissions:
20882074
type: integer
20892075
description: number of submissions
@@ -2154,7 +2140,7 @@ definitions:
21542140
- name
21552141
- isActive
21562142
- abbreviation
2157-
ChallengeSettingsData:
2143+
ChallengeMetadataData:
21582144
type: object
21592145
properties:
21602146
name:
@@ -2273,17 +2259,17 @@ definitions:
22732259
type: string
22742260
privateDescription:
22752261
type: string
2276-
termsIds:
2262+
terms:
22772263
type : array
22782264
description: The ids of the terms of use to add for the challenge
22792265
items:
22802266
type: string
22812267
format: UUID
2282-
challengeSettings:
2268+
metadata:
22832269
type: array
22842270
items:
22852271
properties:
2286-
type:
2272+
name:
22872273
type: string
22882274
description: The challenge setting type
22892275
format: UUID
@@ -2391,7 +2377,7 @@ definitions:
23912377
type: string
23922378
privateDescription:
23932379
type: string
2394-
challengeSettings:
2380+
metadata:
23952381
type: array
23962382
items:
23972383
properties:
@@ -2478,22 +2464,9 @@ definitions:
24782464
terms:
24792465
type: array
24802466
items:
2481-
properties:
2482-
id:
2483-
type: integer
2484-
description: The terms of use id
2485-
agreeabilityType:
2486-
type: string
2487-
description: the terms of use agreeability type
2488-
title:
2489-
type: string
2490-
description: the terms of use title
2491-
url:
2492-
type: string
2493-
description: the terms of use url
2494-
templateId:
2495-
type: string
2496-
description: the template id of the terms of use (only valid when the terms agreeability type is 'Docusignable')
2467+
type: string
2468+
description: The terms of use id
2469+
format: UUID
24972470
numOfSubmissions:
24982471
type: integer
24992472
description: number of submissions

package-lock.json

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

src/common/helper.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,7 @@ async function getChallengeTerms (termsIds) {
607607
// Get the terms details from the API
608608
try {
609609
const res = await axios.get(`${config.TERMS_API_URL}/${id}?noauth=true`, { headers: { Authorization: `Bearer ${token}` } })
610-
terms.push(_.assign({
611-
id: res.data.id,
612-
agreeabilityType: res.data.agreeabilityType,
613-
title: res.data.title,
614-
url: res.data.url
615-
}, _.isNil(res.data.docusignTemplateId) ? null : { templateId: res.data.docusignTemplateId }))
610+
terms.push(res.data.id)
616611
} catch (e) {
617612
if (_.get(e, 'response.status') === HttpStatus.NOT_FOUND) {
618613
throw new errors.BadRequestError(`Terms of use identified by the id ${id} does not exist`)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Controller for challenge type endpoints
3+
*/
4+
const HttpStatus = require('http-status-codes')
5+
const service = require('../services/ChallengeMetadataService')
6+
const helper = require('../common/helper')
7+
8+
/**
9+
* Search challenge metadata
10+
* @param {Object} req the request
11+
* @param {Object} res the response
12+
*/
13+
async function searchChallengeMetadata (req, res) {
14+
const result = await service.searchChallengeMetadata(req.query)
15+
helper.setResHeaders(req, res, result)
16+
res.send(result.result)
17+
}
18+
19+
/**
20+
* Create challenge metadata
21+
* @param {Object} req the request
22+
* @param {Object} res the response
23+
*/
24+
async function createChallengeMetadata (req, res) {
25+
const result = await service.createChallengeMetadata(req.body)
26+
res.status(HttpStatus.CREATED).send(result)
27+
}
28+
29+
/**
30+
* Get challenge metadata
31+
* @param {Object} req the request
32+
* @param {Object} res the response
33+
*/
34+
async function getChallengeMetadata (req, res) {
35+
const result = await service.getChallengeMetadata(req.params.challengeMetadataId)
36+
res.send(result)
37+
}
38+
39+
/**
40+
* Update challenge metadata
41+
* @param {Object} req the request
42+
* @param {Object} res the response
43+
*/
44+
async function updateChallengeMetadata (req, res) {
45+
const result = await service.updateChallengeMetadata(req.params.challengeMetadataId, req.body)
46+
res.send(result)
47+
}
48+
49+
module.exports = {
50+
searchChallengeMetadata,
51+
createChallengeMetadata,
52+
getChallengeMetadata,
53+
updateChallengeMetadata
54+
}

0 commit comments

Comments
 (0)