Skip to content

Commit 03d5a17

Browse files
Add gitRepoURLs array to challenge model
1 parent c1eefdb commit 03d5a17

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

docs/swagger.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,10 @@ definitions:
17601760
type: array
17611761
items:
17621762
type: string
1763+
gitRepoURLs:
1764+
type: array
1765+
items:
1766+
type: string
17631767
created:
17641768
type: string
17651769
format: date-time
@@ -2065,6 +2069,10 @@ definitions:
20652069
type: array
20662070
items:
20672071
type: string
2072+
gitRepoURLs:
2073+
type: array
2074+
items:
2075+
type: string
20682076
created:
20692077
type: string
20702078
format: date-time

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/models/Challenge.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ const schema = new Schema({
8282
type: Array,
8383
required: false
8484
},
85+
gitRepoURLs: {
86+
type: Array,
87+
required: false
88+
},
8589
created: {
8690
type: Date,
8791
required: true

src/services/ChallengeService.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ async function searchChallenges (currentUser, criteria) {
7878
if (criteria.group) {
7979
boolQuery.push({ match_phrase: { groups: criteria.group } })
8080
}
81+
if (criteria.gitRepoURL) {
82+
boolQuery.push({ match_phrase: { gitRepoURLs: criteria.gitRepoURL } })
83+
}
8184
if (criteria.createdDateStart) {
8285
boolQuery.push({ range: { created: { gte: criteria.createdDateStart } } })
8386
}
@@ -144,6 +147,7 @@ searchChallenges.schema = {
144147
legacyId: Joi.number().integer().positive(),
145148
status: Joi.string().valid(_.values(constants.challengeStatuses)),
146149
group: Joi.string(),
150+
gitRepoURL: Joi.string().uri(),
147151
createdDateStart: Joi.date(),
148152
createdDateEnd: Joi.date(),
149153
updatedDateStart: Joi.date(),
@@ -259,7 +263,8 @@ createChallenge.schema = {
259263
forumId: Joi.number().integer().positive(),
260264
startDate: Joi.date().required(),
261265
status: Joi.string().valid(_.values(constants.challengeStatuses)).required(),
262-
groups: Joi.array().items(Joi.string()) // group names
266+
groups: Joi.array().items(Joi.string()), // group names
267+
gitRepoURLs: Joi.array().items(Joi.string().uri())
263268
}).required(),
264269
userToken: Joi.any()
265270
}
@@ -426,6 +431,7 @@ async function update (currentUser, challengeId, data, userToken, isFull) {
426431
helper.ensureNoDuplicateOrNullElements(data.tags, 'tags')
427432
helper.ensureNoDuplicateOrNullElements(data.attachmentIds, 'attachmentIds')
428433
helper.ensureNoDuplicateOrNullElements(data.groups, 'groups')
434+
helper.ensureNoDuplicateOrNullElements(data.gitRepoURLs, 'gitRepoURLs')
429435

430436
const challenge = await helper.getById('Challenge', challengeId)
431437

@@ -493,6 +499,11 @@ async function update (currentUser, challengeId, data, userToken, isFull) {
493499
_.intersection(challenge[key], value).length !== value.length) {
494500
op = '$PUT'
495501
}
502+
} else if (key === 'gitRepoURLs') {
503+
if (_.isUndefined(challenge[key]) || challenge[key].length !== value.length ||
504+
_.intersection(challenge[key], value).length !== value.length) {
505+
op = '$PUT'
506+
}
496507
} else if (_.isUndefined(challenge[key]) || challenge[key] !== value) {
497508
op = '$PUT'
498509
}
@@ -580,6 +591,24 @@ async function update (currentUser, challengeId, data, userToken, isFull) {
580591
// send null to Elasticsearch to clear the field
581592
data.groups = null
582593
}
594+
if (isFull && _.isUndefined(data.gitRepoURLs) && challenge.gitRepoURLs) {
595+
if (!updateDetails['$DELETE']) {
596+
updateDetails['$DELETE'] = {}
597+
}
598+
updateDetails['$DELETE'].gitRepoURLs = null
599+
auditLogs.push({
600+
id: uuid(),
601+
challengeId,
602+
fieldName: 'gitRepoURLs',
603+
oldValue: JSON.stringify(challenge.gitRepoURLs),
604+
newValue: 'NULL',
605+
created: new Date(),
606+
createdBy: currentUser.handle || currentUser.sub
607+
})
608+
delete challenge.gitRepoURLs
609+
// send null to Elasticsearch to clear the field
610+
data.gitRepoURLs = null
611+
}
583612
if (isFull && _.isUndefined(data.legacyId) && challenge.legacyId) {
584613
if (!updateDetails['$DELETE']) {
585614
updateDetails['$DELETE'] = {}
@@ -730,7 +759,8 @@ partiallyUpdateChallenge.schema = {
730759
legacyId: Joi.number().integer().positive(),
731760
status: Joi.string().valid(_.values(constants.challengeStatuses)),
732761
attachmentIds: Joi.array().items(Joi.optionalId()),
733-
groups: Joi.array().items(Joi.string()) // group names
762+
groups: Joi.array().items(Joi.string()), // group names
763+
gitRepoURLs: Joi.array().items(Joi.string().uri())
734764
}).required(),
735765
userToken: Joi.any()
736766
}

0 commit comments

Comments
 (0)