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 9 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 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
21 changes: 19 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,31 @@ 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) {
const allPendingInvitesForApplication = await models.ProjectMemberInvite.getPendingInvitesForApplication(invite.applicationId);
// If only the current invite is the open one's
// then the application status has to be moved to pending status
if (allPendingInvitesForApplication.length === 0) {
await models.CopilotApplication.update({
status: COPILOT_APPLICATION_STATUS.PENDING,
}, {
where: {
id: invite.applicationId,
},
});
}
}

res.status(204).end();
});
})
Expand Down
19 changes: 18 additions & 1 deletion src/routes/projectMemberInvites/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = [
.update({
status: newStatus,
})
.then((updatedInvite) => {
.then(async (updatedInvite) => {
// emit the event
util.sendResourceToKafkaBus(
req,
Expand Down Expand Up @@ -166,6 +166,23 @@ module.exports = [
return next(e);
}
});
} else if (updatedInvite.status === INVITE_STATUS.REFUSED) {
// update the application if the invite
// originated from copilot opportunity
if (updatedInvite.applicationId) {
const allPendingInvitesForApplication = await models.ProjectMemberInvite.getPendingInvitesForApplication(invite.applicationId);
// If only the current invite is the open one's
// then the application status has to be moved to pending status
if (allPendingInvitesForApplication.length === 0) {
await models.CopilotApplication.update({
status: COPILOT_APPLICATION_STATUS.PENDING,
}, {
where: {
id: updatedInvite.applicationId,
},
});
}
}
}
return res.json(util.postProcessInvites('$.email', updatedInvite, req));
});
Expand Down