Skip to content

Commit 5151cfa

Browse files
authored
Merge pull request #810 from topcoder-platform/pm-1168_2
fix(PM-1168): QA feedbacks for assigning copilots
2 parents 6224d47 + ea2ac33 commit 5151cfa

File tree

6 files changed

+49
-6
lines changed

6 files changed

+49
-6
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ workflows:
149149
context : org-global
150150
filters:
151151
branches:
152-
only: ['develop', 'migration-setup']
152+
only: ['develop', 'migration-setup', 'pm-1168_2']
153153
- deployProd:
154154
context : org-global
155155
filters:

src/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const COPILOT_REQUEST_STATUS = {
1515
REJECTED: 'rejected',
1616
SEEKING: 'seeking',
1717
CANCELED: 'canceled',
18-
FULFILLED: 'fulfiled',
18+
FULFILLED: 'fulfilled',
1919
};
2020

2121
export const COPILOT_APPLICATION_STATUS = {

src/models/projectMemberInvite.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ module.exports = function defineProjectMemberInvite(sequelize, DataTypes) {
6565
raw: true,
6666
});
6767

68+
ProjectMemberInvite.getPendingInvitesForApplication = applicationId => ProjectMemberInvite.findAll({
69+
where: {
70+
applicationId,
71+
status: INVITE_STATUS.PENDING,
72+
},
73+
raw: true,
74+
});
75+
6876
ProjectMemberInvite.getPendingAndReguestedInvitesForProject = projectId => ProjectMemberInvite.findAll({
6977
where: {
7078
projectId,

src/routes/copilotOpportunity/assign.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = [
4848
}
4949

5050
const application = await models.CopilotApplication.findOne({
51-
where: { id: applicationId },
51+
where: { id: applicationId, opportunityId: copilotOpportunityId },
5252
transaction: t,
5353
});
5454

@@ -99,6 +99,7 @@ module.exports = [
9999
}
100100

101101
const applicationUser = await util.getMemberDetailsByUserIds([userId], req.log, req.id);
102+
req.log.info(applicationUser, 'applicationUser asdsd', userId);
102103

103104
const invite = await models.ProjectMemberInvite.create({
104105
status: INVITE_STATUS.PENDING,

src/routes/projectMemberInvites/delete.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import _ from 'lodash';
22
import { middleware as tcMiddleware } from 'tc-core-library-js';
33
import models from '../../models';
44
import util from '../../util';
5-
import { PROJECT_MEMBER_ROLE, INVITE_STATUS, EVENT, RESOURCES } from '../../constants';
5+
import { PROJECT_MEMBER_ROLE, INVITE_STATUS, EVENT, RESOURCES, COPILOT_APPLICATION_STATUS } from '../../constants';
66
import { PERMISSION } from '../../permissions/constants';
77

88
/**
@@ -74,14 +74,31 @@ module.exports = [
7474
.update({
7575
status: INVITE_STATUS.CANCELED,
7676
})
77-
.then((updatedInvite) => {
77+
.then(async (updatedInvite) => {
7878
// emit the event
7979
util.sendResourceToKafkaBus(
8080
req,
8181
EVENT.ROUTING_KEY.PROJECT_MEMBER_INVITE_REMOVED,
8282
RESOURCES.PROJECT_MEMBER_INVITE,
8383
updatedInvite.toJSON());
8484

85+
// update the application if the invite
86+
// originated from copilot opportunity
87+
if (invite.applicationId) {
88+
const allPendingInvitesForApplication = await models.ProjectMemberInvite.getPendingInvitesForApplication(invite.applicationId);
89+
// If only the current invite is the open one's
90+
// then the application status has to be moved to pending status
91+
if (allPendingInvitesForApplication.length === 0) {
92+
await models.CopilotApplication.update({
93+
status: COPILOT_APPLICATION_STATUS.PENDING,
94+
}, {
95+
where: {
96+
id: invite.applicationId,
97+
},
98+
});
99+
}
100+
}
101+
85102
res.status(204).end();
86103
});
87104
})

src/routes/projectMemberInvites/update.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ module.exports = [
8181
.update({
8282
status: newStatus,
8383
})
84-
.then((updatedInvite) => {
84+
.then(async (updatedInvite) => {
8585
// emit the event
8686
util.sendResourceToKafkaBus(
8787
req,
@@ -166,6 +166,23 @@ module.exports = [
166166
return next(e);
167167
}
168168
});
169+
} else if (updatedInvite.status === INVITE_STATUS.REFUSED) {
170+
// update the application if the invite
171+
// originated from copilot opportunity
172+
if (updatedInvite.applicationId) {
173+
const allPendingInvitesForApplication = await models.ProjectMemberInvite.getPendingInvitesForApplication(invite.applicationId);
174+
// If only the current invite is the open one's
175+
// then the application status has to be moved to pending status
176+
if (allPendingInvitesForApplication.length === 0) {
177+
await models.CopilotApplication.update({
178+
status: COPILOT_APPLICATION_STATUS.PENDING,
179+
}, {
180+
where: {
181+
id: updatedInvite.applicationId,
182+
},
183+
});
184+
}
185+
}
169186
}
170187
return res.json(util.postProcessInvites('$.email', updatedInvite, req));
171188
});

0 commit comments

Comments
 (0)