Skip to content

feat(PM-1168): Added API to assign an opportunity with an applicant #805

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

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

hentrymartin
Copy link
Collaborator

What's in this PR?

  • Added an API to assign an opportunity with an applicant
  • Added status to existing copilot applications table

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

@hentrymartin hentrymartin requested a review from kkartunov May 12, 2025 18:56

const existingUser = activeMembers.find(item => item.userId === userId);

if (existingUser) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should check if existing user is a copilot in the project not just that they are member of a project.

details: JSON.stringify({ message: 'You do not have permission to assign a copilot opportunity' }),
status: 403,
});
return next(err);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is next a promise? Returning a callback function won't revert the transaction, what do you think?

}
});

res.status(200).send({id: applicationId});
Copy link
Contributor

Choose a reason for hiding this comment

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

I am missing the requirement "Mark the related to opportunity copilot request as FULFILLED".
Where is this implemented?

where: {
opportunityId: opportunityId,
opportunityId,

Choose a reason for hiding this comment

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

The property opportunityId is using shorthand syntax. Ensure that this is intentional and consistent with the rest of the codebase.


return models.sequelize.transaction(async (t) => {
const opportunity = await models.CopilotOpportunity.findOne({
where: { id: copilotOpportunityId },

Choose a reason for hiding this comment

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

Consider adding error handling for the database transaction itself to ensure that any issues during the transaction are properly caught and handled.

}

const application = await models.CopilotApplication.findOne({
where: { id: applicationId },

Choose a reason for hiding this comment

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

The transaction: t option is correctly added to the findOne method, but ensure that all database operations within the transaction are consistently using this option to maintain atomicity.

}

await models.CopilotRequest.update(
{ status: COPILOT_REQUEST_STATUS.FULFILLED },

Choose a reason for hiding this comment

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

Ensure that the transaction: t option is used consistently across all update operations to maintain atomicity within the transaction.

{ where: { id: applicationId }, transaction: t },
);

res.status(200).send({ id: applicationId });

Choose a reason for hiding this comment

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

Consider adding a final catch block after the transaction to handle any errors that might occur during the transaction and ensure a proper rollback if necessary.

@@ -63,16 +63,16 @@ module.exports = [
res.status(200).json(existingApplication);
return Promise.resolve();
}

Choose a reason for hiding this comment

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

Remove unnecessary whitespace change to keep the code clean and consistent.

util.handleError('Error creating copilot application', err, req, next);
return next(err);
});
util.handleError('Error creating copilot application', err, req, next);

Choose a reason for hiding this comment

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

Ensure consistent indentation for the .catch block to improve readability.

@@ -295,13 +295,12 @@ module.exports = [
// whom we are inviting, because Member Service has a loose search logic and may return
// users with handles whom we didn't search for
.then((foundUsers) => {
if(invite.handles) {
if (invite.handles) {

Choose a reason for hiding this comment

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

There should be a space between if and the opening parenthesis for consistency with the rest of the code style.

return []
}

return [];

Choose a reason for hiding this comment

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

Ensure consistent use of semicolons. The semicolon at the end of the return []; statement is correct, but make sure this style is consistent throughout the codebase.

@@ -443,7 +442,7 @@ module.exports = [
}
});
}).catch((err) => {
console.log(err)
console.log(err);

Choose a reason for hiding this comment

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

Using console.log for error handling is not recommended in production code. Consider using a proper logging mechanism or error handling strategy.

@kkartunov kkartunov self-requested a review May 14, 2025 16:02
Copy link
Contributor

@kkartunov kkartunov left a comment

Choose a reason for hiding this comment

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

Looks good

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