Skip to content

feat(PM-1379): cancel copilot opportunity #825

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 6 commits into from
Jun 19, 2025
Merged

feat(PM-1379): cancel copilot opportunity #825

merged 6 commits into from
Jun 19, 2025

Conversation

hentrymartin
Copy link
Collaborator

What's in this PR?

  • Added API to cancel copilot opportunity

Ticket link - https://topcoder.atlassian.net/browse/PM-1378

const opportunityId = _.parseInt(req.params.id);

return models.sequelize.transaction(async (transaction) => {
req.log.debug('Canceling Copilot opportunity transaction', data);

Choose a reason for hiding this comment

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

The variable data is referenced here but not defined anywhere in the code. This will cause a ReferenceError. Consider defining data or removing its usage.

transaction,
});

applications.update({

Choose a reason for hiding this comment

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

The applications.update method is being called on an array of applications, which will not work as expected. You should iterate over each application and call the update method individually.

transaction,
});

copilotRequest.update({

Choose a reason for hiding this comment

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

The copilotRequest.update method should be awaited to ensure the update operation completes before proceeding.

transaction,
});

opportunity.update({

Choose a reason for hiding this comment

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

The opportunity.update method should be awaited to ensure the update operation completes before proceeding.

@@ -419,6 +419,10 @@ router.route('/v5/projects/copilots/opportunity/:id(\\d+)/applications')
router.route('/v5/projects/copilots/opportunity/:id(\\d+)/assign')
.post(require('./copilotOpportunity/assign'));

// Cancel Copilot opportunity
router.route('/v5/projects/copilots/opportunity/:id(\\d+)/cancel')
.delete(require('./copilotOpportunity/delete'));

Choose a reason for hiding this comment

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

The file being required here is named delete, which might be misleading since the route is for canceling an opportunity. Consider renaming the file to something more descriptive, like cancel, to better reflect its purpose.

const opportunityId = _.parseInt(req.params.id);

return models.sequelize.transaction(async (transaction) => {
req.log.debug('Canceling Copilot opportunity transaction', opportunityId);

Choose a reason for hiding this comment

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

The log message has been updated to include opportunityId, which is a good improvement for debugging. However, ensure that opportunityId is always a valid integer before logging to avoid potential issues with malformed input.

transaction,
});

const applications = await models.CopilotApplication.findAll({

Choose a reason for hiding this comment

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

The model name CopilotApplications was changed to CopilotApplication. Ensure that this change is consistent across the entire codebase to prevent any potential issues with model references.

transaction,
});

applications.forEach(async (application) => {

Choose a reason for hiding this comment

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

The use of forEach with async/await may not work as expected because forEach does not wait for promises to resolve. Consider using a for...of loop or Promise.all to ensure that all updates are completed before proceeding.

});

const promises = [];
applications.forEach(async (application) => {

Choose a reason for hiding this comment

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

Using forEach with an async function does not wait for the promises to resolve. Consider using a for...of loop or Promise.all to ensure all updates are completed before proceeding.

@hentrymartin hentrymartin merged commit 69fe32b into develop Jun 19, 2025
2 checks passed
@hentrymartin hentrymartin deleted the pm-1378 branch June 19, 2025 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants