Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ module.exports = {
COPILOT: 'Copilot',
MANAGER: 'Manager',
SUBMITTER: 'Submitter'
},
CHALLENGE_STATUSES: {
NEW: 'New',
DRAFT: 'Draft',
CANCELLED: 'Cancelled',
ACTIVE: 'Active',
COMPLETED: 'Completed',
DELETED: 'Deleted',
CANCELLED_FAILED_REVIEW: 'Cancelled - Failed Review',
CANCELLED_FAILED_SCREENING: 'Cancelled - Failed Screening',
CANCELLED_ZERO_SUBMISSIONS: 'Cancelled - Zero Submissions',
CANCELLED_WINNER_UNRESPONSIVE: 'Cancelled - Winner Unresponsive',
CANCELLED_CLIENT_REQUEST: 'Cancelled - Client Request',
CANCELLED_REQUIREMENTS_INFEASIBLE: 'Cancelled - Requirements Infeasible',
CANCELLED_ZERO_REGISTRATIONS: 'Cancelled - Zero Registrations'
}
},
VANILLA: {
Expand Down
28 changes: 24 additions & 4 deletions src/services/vanilla.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ async function createVanillaGroup (challenge) {
type: groupTemplate.group.type,
description: groupDescriptionTemplate({ challenge }),
challengeID: `${challenge.id}`,
challengeUrl: `${challenge.url}`
challengeUrl: `${challenge.url}`,
archived: true
})

if (!group.groupID) {
Expand All @@ -229,7 +230,8 @@ async function createVanillaGroup (challenge) {
urlcode: `${challenge.id}`,
parentCategoryID: parentCategory[0].categoryID,
displayAs: groupTemplate.categories ? constants.VANILLA.CATEGORY_DISPLAY_STYLE.CATEGORIES : constants.VANILLA.CATEGORY_DISPLAY_STYLE.DISCUSSIONS,
groupID: group.groupID
groupID: group.groupID,
archived: true
})

logger.info(`The '${challengeCategory.name}' category was created`)
Expand All @@ -241,7 +243,8 @@ async function createVanillaGroup (challenge) {
name: item.name,
urlcode: `${urlCodeTemplate({ challenge })}`,
parentCategoryID: challengeCategory.categoryID,
groupID: group.groupID
groupID: group.groupID,
archived: true
})
logger.info(`The '${item.name}' category was created`)
await createDiscussions(group, challenge, item.discussions, childCategory)
Expand Down Expand Up @@ -286,8 +289,25 @@ async function updateVanillaGroup (challenge) {
throw new Error('Multiple groups were found for this challenge')
}

if (challenge.status === constants.TOPCODER.CHALLENGE_STATUSES.ACTIVE) {
await vanillaClient.unarchiveGroup(groups[0].groupID)
logger.info(`The group with groupID=${groups[0].groupID} was unarchived.`)
} else if (_.includes([constants.TOPCODER.CHALLENGE_STATUSES.COMPLETED,
constants.TOPCODER.CHALLENGE_STATUSES.CANCELLED,
constants.TOPCODER.CHALLENGE_STATUSES.CANCELLED_FAILED_REVIEW,
constants.TOPCODER.CHALLENGE_STATUSES.CANCELLED_FAILED_SCREENING,
constants.TOPCODER.CHALLENGE_STATUSES.CANCELLED_ZERO_SUBMISSIONS,
constants.TOPCODER.CHALLENGE_STATUSES.CANCELLED_WINNER_UNRESPONSIVE,
constants.TOPCODER.CHALLENGE_STATUSES.CANCELLED_CLIENT_REQUEST,
constants.TOPCODER.CHALLENGE_STATUSES.CANCELLED_REQUIREMENTS_INFEASIBLE,
constants.TOPCODER.CHALLENGE_STATUSES.CANCELLED_ZERO_REGISTRATIONS,
constants.TOPCODER.CHALLENGE_STATUSES.DELETED], challenge.status)) {
await vanillaClient.archiveGroup(groups[0].groupID)
logger.info(`The group with groupID=${groups[0].groupID} was archived.`)
}

const { body: updatedGroup } = await vanillaClient.updateGroup(groups[0].groupID, { name: challenge.name })
logger.info(`The group was updated: ${JSON.stringify(updatedGroup)}`)
logger.info(`The group with groupID=${groups[0].groupID} was updated: ${JSON.stringify(updatedGroup)}`)

const { body: groupCategory } = await vanillaClient.getCategoryByUrlcode(`${challenge.id}`)
if (!groupCategory) {
Expand Down
8 changes: 8 additions & 0 deletions src/utils/vanilla-client.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ function getVanillaClient () {
.query({ access_token: config.VANILLA.ADMIN_ACCESS_TOKEN })
.send(data)
},
archiveGroup: (groupId) => {
return request.put(`${config.VANILLA.API_URL}/groups/${groupId}/archive`)
.query({ access_token: config.VANILLA.ADMIN_ACCESS_TOKEN })
},
unarchiveGroup: (groupId) => {
return request.put(`${config.VANILLA.API_URL}/groups/${groupId}/unarchive`)
.query({ access_token: config.VANILLA.ADMIN_ACCESS_TOKEN })
},
searchGroups: (query) => {
const queryParams = { access_token: config.VANILLA.ADMIN_ACCESS_TOKEN }
queryParams.challengeID = query
Expand Down