Skip to content

Commit 7e1f9ef

Browse files
#193 - Add new submittedDate and reviewedDate attributes to the models
1 parent daa7453 commit 7e1f9ef

File tree

8 files changed

+129
-28
lines changed

8 files changed

+129
-28
lines changed

docs/swagger.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ paths:
9595
legacySubmissionId: 'a12a4180-65aa-42ec-a945-5fd21dec0502'
9696
legacyUploadId: 'a12a4180-65aa-42ec-a945-5fd21dec0502'
9797
submissionPhaseId: 764567
98+
submittedDate: '2018-05-20T07:00:30.123Z'
9899
created: '2018-05-20T07:00:30.123Z'
99100
updated: '2018-06-01T07:36:28.178Z'
100101
createdBy: 'topcoder user'
@@ -107,6 +108,7 @@ paths:
107108
legacySubmissionId: 'a12a4180-65aa-42ec-a945-5fd21dec0502'
108109
legacyUploadId: 'a12a4180-65aa-42ec-a945-5fd21dec0502'
109110
submissionPhaseId: 764567
111+
submittedDate: '2018-05-20T08:00:30.000Z'
110112
created: '2018-05-20T08:00:30.000Z'
111113
updated: '2018-06-01T09:23:00.178Z'
112114
createdBy: 'topcoder user'
@@ -205,6 +207,7 @@ paths:
205207
Create a new submission.
206208
207209
**Authorization:** Submission creation is accessible by roles `topcoder user`, `admin` and `copilot`.
210+
**Note** Value for `submittedDate` attribute can only be provided by users with `admin` role
208211
tags:
209212
- Submissions
210213
operationId: createSubmission
@@ -262,6 +265,11 @@ paths:
262265
name: submissionPhaseId
263266
type: integer
264267
description: Submission Phase Id
268+
- in: formData
269+
name: submittedDate
270+
type: string
271+
format: date-time
272+
description: Date of submission (defaults to submission creation date if none passed)
265273
responses:
266274
201:
267275
description: Created - The request was successful and the resource is returned.
@@ -612,6 +620,7 @@ paths:
612620
scoreCardId: 123456789
613621
isPassing: false
614622
isFinal: false
623+
reviewedDate: '2018-05-20T07:00:30.123Z'
615624
created: '2018-05-20T07:00:30.123Z'
616625
updated: '2018-06-01T07:36:28.178Z'
617626
createdBy: copilot
@@ -622,6 +631,7 @@ paths:
622631
scoreCardId: 123456789
623632
isPassing: true
624633
isFinal: true
634+
reviewedDate: '2018-05-20T07:00:30.123Z'
625635
created: '2018-05-20T07:00:30.123Z'
626636
updated: '2018-06-01T07:36:28.178Z'
627637
createdBy: copilot
@@ -931,6 +941,7 @@ paths:
931941
scoreCardId: 123456789
932942
submissionId: 'd67a4180-65aa-42ec-a945-5fd21dec0503'
933943
status: 'queued'
944+
reviewedDate: '2018-05-20T07:00:30.123Z'
934945
created: '2018-05-20T07:00:30.123Z'
935946
updated: '2018-06-01T07:36:28.178Z'
936947
createdBy: 'admin'
@@ -942,6 +953,7 @@ paths:
942953
scoreCardId: 123456789
943954
submissionId: 'd23a4180-65aa-42ec-a945-5fd21dec0503'
944955
status: 'completed'
956+
reviewedDate: '2018-05-20T07:00:30.123Z'
945957
created: '2018-05-20T07:00:30.123Z'
946958
updated: '2018-06-01T07:36:28.178Z'
947959
createdBy: 'admin'
@@ -1880,6 +1892,11 @@ definitions:
18801892
type: integer
18811893
description: The submission phase id.
18821894
example: '5dea6d9e-161a-4c7a-b316-597c73a7b8f4'
1895+
submittedDate:
1896+
type: string
1897+
format: date-time
1898+
description: Date of submission (defaults to submission creation date if none passed)
1899+
example: '2018-05-20T07:00:30.123Z'
18831900

18841901
UpdatableSubmission:
18851902
description: The submission entity fields that updates whole entity.
@@ -1939,6 +1956,11 @@ definitions:
19391956
metadata:
19401957
type: object
19411958
description: Review summation metadata in JSON format
1959+
reviewedDate:
1960+
type: string
1961+
format: date-time
1962+
description: Date of review summation (defaults to review summation creation date if none passed)
1963+
example: '2018-05-20T07:00:30.123Z'
19421964

19431965
UpdatableReviewSummation:
19441966
description: The review summation entity fields that updates whole entity.
@@ -2006,6 +2028,11 @@ definitions:
20062028
metadata:
20072029
type: object
20082030
description: Review Metadata in JSON format
2031+
reviewedDate:
2032+
type: string
2033+
format: date-time
2034+
description: Date of review (defaults to review creation date if none passed)
2035+
example: '2018-05-20T07:00:30.123Z'
20092036

20102037
UpdatableReview:
20112038
description: The review entity fields that updates whole entity.

package-lock.json

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

scripts/createIndex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ co(function * createIndex () {
1717
// fields not specified below will be 'text' by default
1818
properties: {
1919
resource: { type: 'keyword' },
20-
challengeId: { type: 'long' },
20+
challengeId: { type: 'keyword' },
2121
memberId: { type: 'keyword' },
2222
type: { type: 'keyword' },
2323
isFileSubmission: { type: 'boolean' },

scripts/data/Reviews.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
},
5050
{
5151
"id": "d24d4180-65aa-42ec-a945-5fd21dec0505",
52-
"score": 100,
52+
"score": 100.0,
5353
"typeId": "f28b2725-ef90-4495-af59-ceb2bd98fc10",
5454
"reviewerId": "c23a4180-65aa-42ec-a945-5fd21dec0503",
5555
"scoreCardId": 123456789,
@@ -85,7 +85,7 @@
8585
},
8686
{
8787
"id": "d24d4180-65aa-42ec-a945-5fd21dec0508",
88-
"score": 100,
88+
"score": 100.0,
8989
"typeId": "f28b2725-ef90-4495-af59-ceb2bd98fc10",
9090
"reviewerId": "c23a4180-65aa-42ec-a945-5fd21dec0503",
9191
"scoreCardId": 123456789,

scripts/data/Submissions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
},
110110
{
111111
"id": "d24d4180-65aa-42ec-a945-5fd21dec0505",
112-
"score": 100,
112+
"score": 100.0,
113113
"typeId": "f28b2725-ef90-4495-af59-ceb2bd98fc10",
114114
"reviewerId": "c23a4180-65aa-42ec-a945-5fd21dec0503",
115115
"scoreCardId": 123456789,
@@ -183,7 +183,7 @@
183183
"review": [
184184
{
185185
"id": "d24d4180-65aa-42ec-a945-5fd21dec0508",
186-
"score": 100,
186+
"score": 100.0,
187187
"typeId": "f28b2725-ef90-4495-af59-ceb2bd98fc10",
188188
"reviewerId": "c23a4180-65aa-42ec-a945-5fd21dec0503",
189189
"scoreCardId": 123456789,

src/services/ReviewService.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ function * createReview (authUser, entity) {
144144
entity
145145
)
146146

147+
if (_.intersection(authUser.roles, ['Administrator', 'administrator']).length === 0 && !authUser.scopes) {
148+
if (entity.reviewedDate) {
149+
throw new errors.HttpStatusError(403, 'You are not allowed to set the `reviewedDate` attribute on a review')
150+
}
151+
} else {
152+
item.reviewedDate = entity.reviewedDate || item.created
153+
}
154+
147155
// Prepare record to be inserted
148156
const record = {
149157
TableName: table,
@@ -202,7 +210,8 @@ createReview.schema = {
202210
.uuid()
203211
.required(),
204212
status: joi.reviewStatus(),
205-
metadata: joi.object()
213+
metadata: joi.object(),
214+
reviewedDate: joi.string()
206215
})
207216
.required()
208217
}
@@ -237,7 +246,7 @@ function * _updateReview (authUser, reviewId, entity) {
237246
},
238247
UpdateExpression: `set score = :s, scoreCardId = :sc, submissionId = :su,
239248
typeId = :t, reviewerId = :r, #st = :st,
240-
updated = :ua, updatedBy = :ub`,
249+
updated = :ua, updatedBy = :ub, reviewedDate = :rd`,
241250
ExpressionAttributeValues: {
242251
':s': entity.score || exist.score,
243252
':sc': entity.scoreCardId || exist.scoreCardId,
@@ -246,7 +255,8 @@ function * _updateReview (authUser, reviewId, entity) {
246255
':r': entity.reviewerId || exist.reviewerId,
247256
':st': entity.status || exist.status || 'completed',
248257
':ua': currDate,
249-
':ub': authUser.handle || authUser.sub
258+
':ub': authUser.handle || authUser.sub,
259+
':rd': entity.reviewedDate || exist.reviewedDate || exist.created
250260
},
251261
ExpressionAttributeNames: {
252262
'#st': 'status'
@@ -278,7 +288,8 @@ function * _updateReview (authUser, reviewId, entity) {
278288
resource: helper.camelize(table),
279289
id: reviewId,
280290
updated: currDate,
281-
updatedBy: authUser.handle || authUser.sub
291+
updatedBy: authUser.handle || authUser.sub,
292+
reviewedDate: entity.reviewedDate || exist.reviewedDate || exist.created
282293
},
283294
entity
284295
)
@@ -291,7 +302,8 @@ function * _updateReview (authUser, reviewId, entity) {
291302
// Hence returning the response which will be in compliance with Swagger
292303
return _.extend(exist, entity, {
293304
updated: currDate,
294-
updatedBy: authUser.handle || authUser.sub
305+
updatedBy: authUser.handle || authUser.sub,
306+
reviewedDate: entity.reviewedDate || exist.reviewedDate || exist.created
295307
})
296308
}
297309

@@ -330,7 +342,8 @@ updateReview.schema = {
330342
.uuid()
331343
.required(),
332344
status: joi.reviewStatus(),
333-
metadata: joi.object()
345+
metadata: joi.object(),
346+
reviewedDate: joi.string()
334347
})
335348
.required()
336349
}
@@ -359,7 +372,8 @@ patchReview.schema = {
359372
scoreCardId: joi.id(),
360373
submissionId: joi.string().uuid(),
361374
status: joi.reviewStatus(),
362-
metadata: joi.object()
375+
metadata: joi.object(),
376+
reviewedDate: joi.string()
363377
})
364378
}
365379

src/services/ReviewSummationService.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ function * createReviewSummation (authUser, entity) {
102102
item.isFinal = entity.isFinal
103103
}
104104

105+
if (_.intersection(authUser.roles, ['Administrator', 'administrator']).length === 0 && !authUser.scopes) {
106+
if (entity.reviewedDate) {
107+
throw new errors.HttpStatusError(403, 'You are not allowed to set the `reviewedDate` attribute on a review summation')
108+
}
109+
} else {
110+
item.reviewedDate = entity.reviewedDate || item.created
111+
}
112+
105113
const record = {
106114
TableName: table,
107115
Item: item
@@ -135,7 +143,8 @@ createReviewSummation.schema = {
135143
aggregateScore: joi.score().required(),
136144
isPassing: joi.boolean().required(),
137145
isFinal: joi.boolean(),
138-
metadata: joi.object()
146+
metadata: joi.object(),
147+
reviewedDate: joi.string()
139148
}).required()
140149
}
141150

@@ -173,14 +182,15 @@ function * _updateReviewSummation (authUser, reviewSummationId, entity) {
173182
id: reviewSummationId
174183
},
175184
UpdateExpression: `set aggregateScore = :s, scoreCardId = :sc, submissionId = :su,
176-
isPassing = :ip, updated = :ua, updatedBy = :ub`,
185+
isPassing = :ip, updated = :ua, updatedBy = :ub, reviewedDate = :rd`,
177186
ExpressionAttributeValues: {
178187
':s': entity.aggregateScore || exist.aggregateScore,
179188
':sc': entity.scoreCardId || exist.scoreCardId,
180189
':su': entity.submissionId || exist.submissionId,
181190
':ip': isPassing,
182191
':ua': currDate,
183-
':ub': authUser.handle || authUser.sub
192+
':ub': authUser.handle || authUser.sub,
193+
':rd': entity.reviewedDate || exist.reviewedDate || exist.created
184194
}
185195
}
186196

@@ -217,7 +227,8 @@ function * _updateReviewSummation (authUser, reviewSummationId, entity) {
217227
resource: helper.camelize(table),
218228
id: reviewSummationId,
219229
updated: currDate,
220-
updatedBy: authUser.handle || authUser.sub
230+
updatedBy: authUser.handle || authUser.sub,
231+
reviewedDate: entity.reviewedDate || exist.reviewedDate || exist.created
221232
}, entity)
222233
}
223234

@@ -226,7 +237,15 @@ function * _updateReviewSummation (authUser, reviewSummationId, entity) {
226237

227238
// Updating records in DynamoDB doesn't return any response
228239
// Hence returning the response which will be in compliance with Swagger
229-
return _.extend(exist, entity, { updated: currDate, updatedBy: authUser.handle || authUser.sub })
240+
return _.extend(
241+
exist,
242+
entity,
243+
{
244+
updated: currDate,
245+
updatedBy: authUser.handle || authUser.sub,
246+
reviewedDate: entity.reviewedDate || exist.reviewedDate || exist.created
247+
}
248+
)
230249
}
231250

232251
/**
@@ -249,7 +268,8 @@ updateReviewSummation.schema = {
249268
aggregateScore: joi.score().required(),
250269
isPassing: joi.boolean().required(),
251270
isFinal: joi.boolean(),
252-
metadata: joi.object()
271+
metadata: joi.object(),
272+
reviewedDate: joi.string()
253273
}).required()
254274
}
255275

@@ -273,7 +293,8 @@ patchReviewSummation.schema = {
273293
aggregateScore: joi.score(),
274294
isPassing: joi.boolean(),
275295
isFinal: joi.boolean(),
276-
metadata: joi.object()
296+
metadata: joi.object(),
297+
reviewedDate: joi.string()
277298
})
278299
}
279300

0 commit comments

Comments
 (0)