Skip to content

Fix/plat 2567 #605

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

Merged
merged 5 commits into from
Mar 29, 2023
Merged
Changes from 2 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
12 changes: 12 additions & 0 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,18 @@ async function updateChallenge(currentUser, challengeId, data) {
logger.debug(`There was an error trying to update the project: ${e.message}`);
}
}

Copy link
Contributor

@rakibansary rakibansary Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

We have the exact same check in another section. Let's avoid code duplication. Our last refactor extracted out common code to helper methods.

If the execution branch you introduced is different from the existing branch, the common code should move to a helper method with the different conditions at the top. For example

if (primaryConditionsAreSatisfied()) // chalengeStatuses in [ requirements infeasible, cancelled payment failed ]
  if (conditionASatisfied() || conditionBSatisfied()) {
     projectHelper.cancelProject()
  }

This lets us immediately understand the conditions under which a project maybe cancelled. This commit introduces redundancy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! It introduces redundancy because I missed checking in the commit where I removed the duplicate code. Please check again

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We set the value of the variable isChallengeBeingCancelled but we never use it. Since the section you are updating has to do with challenge cancellation, we should double check if there's any need for isChallengeBeingCancelled and either add back functionality that we had before that we might have missed due to the refactor, or remove isChallengeBeingCancelled

if (
data.status === constants.challengeStatuses.CancelledRequirementsInfeasible ||
data.status === constants.challengeStatuses.CancelledPaymentFailed
) {
try {
await helper.cancelProject(challenge.projectId, cancelReason, currentUser);
} catch (e) {
logger.debug(`There was an error trying to cancel the project: ${e.message}`);
}
sendRejectedEmail = true;
}
}

/* END self-service stuffs */
Expand Down