Skip to content

fix(PM-1168): QA feedbacks for assigning copilots #810

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 12 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ workflows:
context : org-global
filters:
branches:
only: ['develop', 'migration-setup']
only: ['develop', 'migration-setup', 'pm-1168_2']
- deployProd:
context : org-global
filters:
Expand Down
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const COPILOT_REQUEST_STATUS = {
REJECTED: 'rejected',
SEEKING: 'seeking',
CANCELED: 'canceled',
FULFILLED: 'fulfiled',
FULFILLED: 'fulfilled',
};

export const COPILOT_APPLICATION_STATUS = {
Expand Down
8 changes: 8 additions & 0 deletions src/models/projectMemberInvite.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ module.exports = function defineProjectMemberInvite(sequelize, DataTypes) {
raw: true,
});

ProjectMemberInvite.getPendingInvitesForApplication = applicationId => ProjectMemberInvite.findAll({
where: {
applicationId,
status: INVITE_STATUS.PENDING,
},
raw: true,
});

ProjectMemberInvite.getPendingAndReguestedInvitesForProject = projectId => ProjectMemberInvite.findAll({
where: {
projectId,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/copilotOpportunity/assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = [
}

const application = await models.CopilotApplication.findOne({
where: { id: applicationId },
where: { id: applicationId, opportunityId: copilotOpportunityId },
transaction: t,
});

Expand Down
24 changes: 22 additions & 2 deletions src/routes/projectMemberInvites/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from 'lodash';
import { middleware as tcMiddleware } from 'tc-core-library-js';
import models from '../../models';
import util from '../../util';
import { PROJECT_MEMBER_ROLE, INVITE_STATUS, EVENT, RESOURCES } from '../../constants';
import { PROJECT_MEMBER_ROLE, INVITE_STATUS, EVENT, RESOURCES, COPILOT_APPLICATION_STATUS } from '../../constants';
import { PERMISSION } from '../../permissions/constants';

/**
Expand Down Expand Up @@ -74,14 +74,34 @@ module.exports = [
.update({
status: INVITE_STATUS.CANCELED,
})
.then((updatedInvite) => {
.then(async (updatedInvite) => {
// emit the event
util.sendResourceToKafkaBus(
req,
EVENT.ROUTING_KEY.PROJECT_MEMBER_INVITE_REMOVED,
RESOURCES.PROJECT_MEMBER_INVITE,
updatedInvite.toJSON());

// update the application if the invite
// originated from copilot opportunity
if (invite.applicationId) {
req.log.info("Invite originated from the application id", invite.applicationId);
const allPendingInvitesForApplication = await models.Sequelize.ProjectMemberInvite.getPendingInvitesForApplication(invite.applicationId);

req.log.info("All pending invites which are open", allPendingInvitesForApplication);
// If only the current invite is the open one's
// then the application status has to be moved to pending status
if (allPendingInvitesForApplication.length === 1) {
await models.Sequelize.CopilotApplication.update({
status: COPILOT_APPLICATION_STATUS.PENDING,
}, {
where: {
id: invite.applicationId,
},
});
}
}

res.status(204).end();
});
})
Expand Down