Skip to content

Commit 9ccc0bb

Browse files
author
Dushyant Bhalgami
authored
Merge pull request #152 from topcoder-platform/develop
updated createReview schema for null score for queued submission
2 parents eff7c2f + 2bbe85c commit 9ccc0bb

22 files changed

+949
-419
lines changed

package-lock.json

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

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"chai": "^4.1.2",
5151
"chai-http": "^4.0.0",
5252
"co-mocha": "^1.2.2",
53+
"husky": "^3.0.5",
5354
"mocha": "^5.2.0",
5455
"mocha-prepare": "^0.1.0",
5556
"nock": "^9.4.3",
@@ -64,5 +65,10 @@
6465
"env": [
6566
"mocha"
6667
]
68+
},
69+
"husky": {
70+
"hooks": {
71+
"pre-commit": "npm run lint"
72+
}
6773
}
6874
}

scripts/ESloadHelper.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ function deleteDatafromES () {
3333
function * loadReviewTypes () {
3434
const promises = []
3535
reviewTypes.forEach((reviewType) => {
36-
let record = {
36+
const record = {
3737
index: config.get('esConfig.ES_INDEX'),
3838
type: config.get('esConfig.ES_TYPE'),
3939
id: reviewType.id,
40-
body: _.extend({'resource': 'reviewType'}, reviewType)
40+
body: _.extend({ resource: 'reviewType' }, reviewType)
4141
}
4242
promises.push(esClient.create(record))
4343
})
@@ -50,11 +50,11 @@ function * loadReviewTypes () {
5050
function * loadSubmissions () {
5151
const promises = []
5252
submissions.forEach((submission) => {
53-
let record = {
53+
const record = {
5454
index: config.get('esConfig.ES_INDEX'),
5555
type: config.get('esConfig.ES_TYPE'),
5656
id: submission.id,
57-
body: _.extend({'resource': 'submission'}, submission)
57+
body: _.extend({ resource: 'submission' }, submission)
5858
}
5959
promises.push(esClient.create(record))
6060
})
@@ -67,11 +67,11 @@ function * loadSubmissions () {
6767
function * loadReviews () {
6868
const promises = []
6969
reviews.forEach((review) => {
70-
let record = {
70+
const record = {
7171
index: config.get('esConfig.ES_INDEX'),
7272
type: config.get('esConfig.ES_TYPE'),
7373
id: review.id,
74-
body: _.extend({'resource': 'review'}, review)
74+
body: _.extend({ resource: 'review' }, review)
7575
}
7676
promises.push(esClient.create(record))
7777
})
@@ -84,11 +84,11 @@ function * loadReviews () {
8484
function * loadReviewSummations () {
8585
const promises = []
8686
reviewSummations.forEach((reviewSummation) => {
87-
let record = {
87+
const record = {
8888
index: config.get('esConfig.ES_INDEX'),
8989
type: config.get('esConfig.ES_TYPE'),
9090
id: reviewSummation.id,
91-
body: _.extend({'resource': 'reviewSummation'}, reviewSummation)
91+
body: _.extend({ resource: 'reviewSummation' }, reviewSummation)
9292
}
9393
promises.push(esClient.create(record))
9494
})

scripts/importData.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,31 @@ co(function * loadData () {
1515
logger.info('Data import started!')
1616
const promises = []
1717
reviewTypes.forEach((reviewType) => {
18-
let record = {
18+
const record = {
1919
TableName: 'ReviewType',
2020
Item: reviewType
2121
}
2222
promises.push(dbhelper.insertRecord(record))
2323
})
2424

2525
submissions.forEach((submission) => {
26-
let record = {
26+
const record = {
2727
TableName: 'Submission',
2828
Item: submission
2929
}
3030
promises.push(dbhelper.insertRecord(record))
3131
})
3232

3333
reviews.forEach((review) => {
34-
let record = {
34+
const record = {
3535
TableName: 'Review',
3636
Item: review
3737
}
3838
promises.push(dbhelper.insertRecord(record))
3939
})
4040

4141
reviewSummations.forEach((reviewSummation) => {
42-
let record = {
42+
const record = {
4343
TableName: 'ReviewSummation',
4444
Item: reviewSummation
4545
}

scripts/migrateFromDBToES.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,23 @@ const esClient = helper.getEsClient()
1919
function * migrateRecords (tableName) {
2020
let promises = []
2121
let batchCounter = 1
22-
let params = {
22+
const params = {
2323
TableName: tableName
2424
}
2525
// Process until all the records from DB is fetched
2626
while (true) {
27-
let records = yield dbhelper.scanRecords(params)
28-
let totalRecords = records.Items.length
27+
const records = yield dbhelper.scanRecords(params)
28+
const totalRecords = records.Items.length
2929
logger.debug(`Number of ${tableName}s fetched from DB - ` + totalRecords)
3030
for (let i = 0; i < totalRecords; i++) {
31-
let record = {
31+
const record = {
3232
index: config.get('esConfig.ES_INDEX'),
3333
type: config.get('esConfig.ES_TYPE'),
3434
id: records.Items[i].id,
35-
body: { doc: _.extend({ resource: helper.camelize(tableName) }, records.Items[i]),
36-
doc_as_upsert: true }
35+
body: {
36+
doc: _.extend({ resource: helper.camelize(tableName) }, records.Items[i]),
37+
doc_as_upsert: true
38+
}
3739
}
3840
promises.push(esClient.update(record))
3941

src/common/dbhelper.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ AWS.config.update({
1919
* @return {Object} DynamoDB Connection Instance
2020
*/
2121
function getDb () {
22-
if (!dbs['conn']) {
23-
dbs['conn'] = new AWS.DynamoDB()
22+
if (!dbs.conn) {
23+
dbs.conn = new AWS.DynamoDB()
2424
}
25-
return dbs['conn']
25+
return dbs.conn
2626
}
2727

2828
/**
2929
* Get DynamoDB Document Client
3030
* @return {Object} DynamoDB Document Client Instance
3131
*/
3232
function getDbClient () {
33-
if (!dbClients['client']) {
34-
dbClients['client'] = new AWS.DynamoDB.DocumentClient()
33+
if (!dbClients.client) {
34+
dbClients.client = new AWS.DynamoDB.DocumentClient()
3535
}
36-
return dbClients['client']
36+
return dbClients.client
3737
}
3838

3939
/**

src/common/helper.js

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ function getBusApiClient () {
8282
*/
8383
function getEsClient () {
8484
const esHost = config.get('esConfig.HOST')
85-
if (!esClients['client']) {
85+
if (!esClients.client) {
8686
// AWS ES configuration is different from other providers
8787
if (/.*amazonaws.*/.test(esHost)) {
88-
esClients['client'] = elasticsearch.Client({
88+
esClients.client = elasticsearch.Client({
8989
apiVersion: config.get('esConfig.API_VERSION'),
9090
hosts: esHost,
9191
connectionClass: require('http-aws-es'), // eslint-disable-line global-require
@@ -95,13 +95,13 @@ function getEsClient () {
9595
}
9696
})
9797
} else {
98-
esClients['client'] = new elasticsearch.Client({
98+
esClients.client = new elasticsearch.Client({
9999
apiVersion: config.get('esConfig.API_VERSION'),
100100
hosts: esHost
101101
})
102102
}
103103
}
104-
return esClients['client']
104+
return esClients.client
105105
}
106106

107107
/*
@@ -135,7 +135,7 @@ function prepESFilter (query, actResource) {
135135
// Adding resource filter
136136
boolQuery.push({ match_phrase: { resource: actResource } })
137137
_.map(filters, (value, key) => {
138-
let pair = {}
138+
const pair = {}
139139
pair[key] = value
140140
if (key.indexOf('.') > -1) {
141141
const resKey = key.split('.')[0]
@@ -182,7 +182,7 @@ function prepESFilter (query, actResource) {
182182
from: (page - 1) * pageSize, // Es Index starts from 0
183183
body: {
184184
_source: {
185-
exclude: [ 'resource' ] // Remove the resource field which is not required
185+
exclude: ['resource'] // Remove the resource field which is not required
186186
},
187187
query: {
188188
bool: {
@@ -196,14 +196,14 @@ function prepESFilter (query, actResource) {
196196

197197
if (sortBy) {
198198
const obj = {}
199-
obj[sortBy] = { 'order': orderBy || 'asc' }
199+
obj[sortBy] = { order: orderBy || 'asc' }
200200
esQuerySortArray.push(obj)
201201
}
202202

203203
// Internal sorting by 'updated' timestamp
204204
if (actResource !== 'reviewType') {
205205
esQuerySortArray.push({
206-
updated: { 'order': 'desc' }
206+
updated: { order: 'desc' }
207207
})
208208
}
209209

@@ -229,10 +229,12 @@ function * fetchFromES (query, resource) {
229229
// Extract data from hits
230230
const rows = _.map(docs.hits.hits, single => single._source)
231231

232-
const response = { 'total': docs.hits.total,
233-
'pageSize': filter.size,
234-
'page': query.page || 1,
235-
'rows': rows }
232+
const response = {
233+
total: docs.hits.total,
234+
pageSize: filter.size,
235+
page: query.page || 1,
236+
rows: rows
237+
}
236238
return response
237239
}
238240

@@ -283,7 +285,7 @@ function setPaginationHeaders (req, res, data) {
283285
'X-Per-Page': data.pageSize,
284286
'X-Total': data.total,
285287
'X-Total-Pages': totalPages,
286-
'Link': link
288+
Link: link
287289
})
288290
}
289291
// Return the data after setting pagination headers
@@ -317,9 +319,9 @@ function * getSubmissionPhaseId (challengeId) {
317319
}
318320
if (response) {
319321
const phases = _.get(response.body, 'result.content', [])
320-
const checkPoint = _.filter(phases, {phaseType: 'Checkpoint Submission', phaseStatus: 'Open'})
321-
const submissionPh = _.filter(phases, {phaseType: 'Submission', phaseStatus: 'Open'})
322-
const finalFixPh = _.filter(phases, {phaseType: 'Final Fix', phaseStatus: 'Open'})
322+
const checkPoint = _.filter(phases, { phaseType: 'Checkpoint Submission', phaseStatus: 'Open' })
323+
const submissionPh = _.filter(phases, { phaseType: 'Submission', phaseStatus: 'Open' })
324+
const finalFixPh = _.filter(phases, { phaseType: 'Final Fix', phaseStatus: 'Open' })
323325
if (checkPoint.length !== 0) {
324326
phaseId = checkPoint[0].id
325327
} else if (submissionPh.length !== 0) {
@@ -367,7 +369,7 @@ function * checkCreateAccess (authUser, subEntity) {
367369
throw new errors.HttpStatusError(403, 'You are not allowed to submit when submission phase is not open')
368370
}
369371

370-
const currPhase = _.filter(phases, {id: submissionPhaseId})
372+
const currPhase = _.filter(phases, { id: submissionPhaseId })
371373

372374
if (currPhase[0].phaseType === 'Final Fix') {
373375
if (!authUser.handle.equals(winner[0].handle)) {
@@ -442,33 +444,35 @@ function * checkGetAccess (authUser, submission) {
442444

443445
// User is either a Reviewer or Screener
444446
if (screener.length !== 0 || reviewer.length !== 0) {
445-
const screeningPhase = _.filter(phases, { phaseType: 'Screening', 'phaseStatus': 'Scheduled' })
446-
const reviewPhase = _.filter(phases, { phaseType: 'Review', 'phaseStatus': 'Scheduled' })
447+
const screeningPhase = _.filter(phases, { phaseType: 'Screening', phaseStatus: 'Scheduled' })
448+
const reviewPhase = _.filter(phases, { phaseType: 'Review', phaseStatus: 'Scheduled' })
447449

448450
// Neither Screening Nor Review is Opened / Closed
449451
if (screeningPhase.length !== 0 && reviewPhase.length !== 0) {
450452
throw new errors.HttpStatusError(403, 'You can access the submission only when Screening / Review is open')
451453
}
452454
} else {
453-
const appealsResponse = _.filter(phases, { phaseType: 'Appeals Response', 'phaseStatus': 'Closed' })
455+
const appealsResponse = _.filter(phases, { phaseType: 'Appeals Response', phaseStatus: 'Closed' })
454456

455457
// Appeals Response is not closed yet
456458
if (appealsResponse.length === 0) {
457459
throw new errors.HttpStatusError(403, 'You cannot access other submissions before the end of Appeals Response phase')
458460
} else {
459-
const userSubmission = yield fetchFromES({ challengeId: submission.challengeId,
460-
memberId: authUser.userId }, camelize('Submission'))
461+
const userSubmission = yield fetchFromES({
462+
challengeId: submission.challengeId,
463+
memberId: authUser.userId
464+
}, camelize('Submission'))
461465
// User requesting submission haven't made any submission
462466
if (userSubmission.total === 0) {
463-
throw new errors.HttpStatusError(403, `You did not submit to the challenge!`)
467+
throw new errors.HttpStatusError(403, 'You did not submit to the challenge!')
464468
}
465469

466470
const reqSubmission = userSubmission.rows[0]
467471
// Only if the requestor has passing score, allow to download other submissions
468472
if (reqSubmission.reviewSummation && reqSubmission.reviewSummation[0].isPassing) {
469473
return true
470474
} else {
471-
throw new errors.HttpStatusError(403, `You should have passed the review to access other member submissions!`)
475+
throw new errors.HttpStatusError(403, 'You should have passed the review to access other member submissions!')
472476
}
473477
}
474478
}
@@ -509,7 +513,7 @@ function * checkReviewGetAccess (authUser, submission) {
509513
logger.info('No access check for Marathon match')
510514
return true
511515
} else {
512-
const appealsResponse = _.filter(phases, { phaseType: 'Appeals Response', 'phaseStatus': 'Closed' })
516+
const appealsResponse = _.filter(phases, { phaseType: 'Appeals Response', phaseStatus: 'Closed' })
513517

514518
// Appeals Response is not closed yet
515519
if (appealsResponse.length === 0) {
@@ -541,15 +545,15 @@ function * downloadFile (fileURL) {
541545
*/
542546
function * postToBusApi (payload) {
543547
const busApiClient = getBusApiClient()
544-
const originalTopic = payload['topic']
548+
const originalTopic = payload.topic
545549

546550
yield busApiClient.postEvent(payload)
547551

548552
// Post to aggregate topic
549-
payload['topic'] = config.get('KAFKA_AGGREGATE_TOPIC')
553+
payload.topic = config.get('KAFKA_AGGREGATE_TOPIC')
550554

551555
// Store the original topic
552-
payload['payload']['originalTopic'] = originalTopic
556+
payload.payload.originalTopic = originalTopic
553557

554558
yield busApiClient.postEvent(payload)
555559
}

src/services/ArtifactService.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ function * _uploadToS3 (file, name) {
4141
*/
4242
function * downloadArtifact (submissionId, fileName) {
4343
// Check the validness of Submission ID
44-
yield HelperService._checkRef({submissionId})
45-
const artifacts = yield s3.listObjects({Bucket: config.aws.ARTIFACT_BUCKET, Prefix: `${submissionId}/${fileName}`}).promise()
44+
yield HelperService._checkRef({ submissionId })
45+
const artifacts = yield s3.listObjects({ Bucket: config.aws.ARTIFACT_BUCKET, Prefix: `${submissionId}/${fileName}` }).promise()
4646
if (artifacts.Contents.length === 0) {
4747
throw new errors.HttpStatusError(400, `Artifact ${fileName} doesn't exist for ${submissionId}`)
4848
}
@@ -65,8 +65,8 @@ downloadArtifact.schema = {
6565
*/
6666
function * listArtifacts (submissionId) {
6767
// Check the validness of Submission ID
68-
yield HelperService._checkRef({submissionId})
69-
const artifacts = yield s3.listObjects({Bucket: config.aws.ARTIFACT_BUCKET, Prefix: submissionId}).promise()
68+
yield HelperService._checkRef({ submissionId })
69+
const artifacts = yield s3.listObjects({ Bucket: config.aws.ARTIFACT_BUCKET, Prefix: submissionId }).promise()
7070
return { artifacts: _.map(artifacts.Contents, (at) => path.parse(at.Key).name) }
7171
}
7272

@@ -93,8 +93,10 @@ function * createArtifact (files, submissionId, entity) {
9393
let exist
9494
// Check the existence of file in S3 bucket
9595
try {
96-
exist = yield s3.headObject({ Bucket: config.aws.ARTIFACT_BUCKET,
97-
Key: fileName}).promise()
96+
exist = yield s3.headObject({
97+
Bucket: config.aws.ARTIFACT_BUCKET,
98+
Key: fileName
99+
}).promise()
98100
} catch (err) {
99101
if (err.statusCode !== 404) throw err
100102
}
@@ -123,8 +125,8 @@ createArtifact.schema = {
123125
*/
124126
function * deleteArtifact (submissionId, fileName) {
125127
// Check the validness of Submission ID
126-
yield HelperService._checkRef({submissionId})
127-
const artifacts = yield s3.listObjects({Bucket: config.aws.ARTIFACT_BUCKET, Prefix: `${submissionId}/${fileName}`}).promise()
128+
yield HelperService._checkRef({ submissionId })
129+
const artifacts = yield s3.listObjects({ Bucket: config.aws.ARTIFACT_BUCKET, Prefix: `${submissionId}/${fileName}` }).promise()
128130
if (artifacts.Contents.length === 0) {
129131
throw new errors.HttpStatusError(404, `Artifact ${fileName} doesn't exist for submission ID: ${submissionId}`)
130132
}

0 commit comments

Comments
 (0)