-
Notifications
You must be signed in to change notification settings - Fork 6
Allow for Topgear Submission type phase when calculating start / end dates (PS-444) #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,8 @@ const { hasAdminRole } = require("./role-helper"); | |
| const { ensureAcessibilityToModifiedGroups } = require("./group-helper"); | ||
| const { ChallengeStatusEnum } = require("@prisma/client"); | ||
|
|
||
| const SUBMISSION_PHASE_PRIORITY = ["Topcoder Submission", "Submission"]; | ||
|
|
||
| class ChallengeHelper { | ||
| /** | ||
| * @param {Object} challenge the challenge object | ||
|
|
@@ -356,7 +358,9 @@ class ChallengeHelper { | |
| enrichChallengeForResponse(challenge, track, type, options = {}) { | ||
| if (challenge.phases && challenge.phases.length > 0) { | ||
| const registrationPhase = _.find(challenge.phases, (p) => p.name === "Registration"); | ||
| const submissionPhase = _.find(challenge.phases, (p) => p.name === "Submission"); | ||
| const submissionPhase = | ||
| _.find(challenge.phases, (p) => p.name === SUBMISSION_PHASE_PRIORITY[0]) || | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| _.find(challenge.phases, (p) => p.name === SUBMISSION_PHASE_PRIORITY[1]); | ||
|
|
||
| // select last started open phase as current phase | ||
| _.forEach(challenge.phases, (p) => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ const Decimal = require("decimal.js"); | |
| const constants = require("../../app-constants"); | ||
| const { PrizeSetTypeEnum } = require("@prisma/client"); | ||
| const { dedupeChallengeTerms } = require("./helper"); | ||
|
|
||
| const SUBMISSION_PHASE_PRIORITY = ["Topcoder Submission", "Submission"]; | ||
| /** | ||
| * Convert phases data to prisma model. | ||
| * | ||
|
|
@@ -11,6 +13,7 @@ const { dedupeChallengeTerms } = require("./helper"); | |
| * @param {Object} auditFields createdBy and updatedBy | ||
| */ | ||
| function convertChallengePhaseSchema(challenge, result, auditFields) { | ||
| const phases = _.isArray(challenge.phases) ? challenge.phases : []; | ||
| // keep phase data | ||
| const phaseFields = [ | ||
| "name", | ||
|
|
@@ -25,24 +28,29 @@ function convertChallengePhaseSchema(challenge, result, auditFields) { | |
| "challengeSource", | ||
| ]; | ||
| // current phase names | ||
| result.currentPhaseNames = _.map( | ||
| _.filter(challenge.phases, (p) => p.isOpen === true), | ||
| "name" | ||
| ); | ||
| // get registration date and submission date | ||
| _.forEach(challenge.phases, (p) => { | ||
| if (p.name === "Registration") { | ||
| result.registrationStartDate = p.actualStartDate || p.scheduledStartDate; | ||
| result.registrationEndDate = p.actualEndDate || p.scheduledEndDate; | ||
| } else if (p.name === "Submission") { | ||
| result.submissionStartDate = p.actualStartDate || p.scheduledStartDate; | ||
| result.submissionEndDate = p.actualEndDate || p.scheduledEndDate; | ||
| } | ||
| }); | ||
| result.currentPhaseNames = _.map(_.filter(phases, (p) => p.isOpen === true), "name"); | ||
|
|
||
| const registrationPhase = _.find(phases, (p) => p.name === "Registration"); | ||
| const submissionPhase = | ||
| _.find(phases, (p) => p.name === SUBMISSION_PHASE_PRIORITY[0]) || | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| _.find(phases, (p) => p.name === SUBMISSION_PHASE_PRIORITY[1]); | ||
|
|
||
| if (registrationPhase) { | ||
| result.registrationStartDate = | ||
| registrationPhase.actualStartDate || registrationPhase.scheduledStartDate; | ||
| result.registrationEndDate = | ||
| registrationPhase.actualEndDate || registrationPhase.scheduledEndDate; | ||
| } | ||
| if (submissionPhase) { | ||
| result.submissionStartDate = | ||
| submissionPhase.actualStartDate || submissionPhase.scheduledStartDate; | ||
| result.submissionEndDate = | ||
| submissionPhase.actualEndDate || submissionPhase.scheduledEndDate; | ||
| } | ||
| // set phases array data | ||
| if (!_.isEmpty(challenge.phases)) { | ||
| if (!_.isEmpty(phases)) { | ||
| result.phases = { | ||
| create: _.map(challenge.phases, (p) => { | ||
| create: _.map(phases, (p) => { | ||
| const phaseData = { | ||
| phase: { connect: { id: p.phaseId } }, | ||
| ..._.pick(p, phaseFields), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[⚠️
performance]Consider using a Set for
SUBMISSION_PHASE_PRIORITYto improve lookup performance when checking phase names. This change can enhance performance, especially if the list grows or is checked frequently.