Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Prevent duplicate v5 challenge creation #94

Merged
merged 1 commit into from
Nov 22, 2022
Merged
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/services/challengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ const challengePropertiesToOmitFromDynamo = [
]

async function save (challenge) {
// Check if challenge is already created
if (!challenge.id) {
try {
const challengesInES = await getChallengeFromES(challenge.legacyId)
if (challengesInES.length === 1) {
logger.debug(`PREVENT DUPLICATE CHALLENGE - ${challenge.legacyId} - V5 already exists ${challengesInES[0].challengeId}`)
challenge.id = challengesInES[0].challengeId
} else if (challengesInES.length > 1) {
// There are more than 1 duplicate challenges
logger.warn(`Challenge ${challenge.legacyId} has ${challengesInES.length} duplicates - ${challengesInES.toString()}`)
}
} catch (e) {
logger.error(`Error fetching V5 challenge ${JSON.stringify(e)}`)
}
}
// logger.debug(`Save - ${challenge.id} - ${challenge.legacyId} - ${JSON.stringify(challenge.prizeSets)}`)
if (challenge.id) {
// logger.debug(`Update Challenge ${challenge.id}`)
Expand Down