Skip to content

Commit 77b0fb0

Browse files
authored
Merge pull request #816 from topcoder-platform/pm-1169_1
fix(PM-1169) Cancel all copilot requests when copilot added via WM
2 parents 388e9f5 + 21b079b commit 77b0fb0

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
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', 'pm-1169']
152+
only: ['develop', 'migration-setup', 'pm-1169_1']
153153
- deployProd:
154154
context : org-global
155155
filters:

src/routes/projectMemberInvites/update.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import validate from 'express-validation';
22
import _ from 'lodash';
33
import Joi from 'joi';
4+
import { Op } from 'sequelize';
45
import { middleware as tcMiddleware } from 'tc-core-library-js';
56
import models from '../../models';
67
import util from '../../util';
78
import { INVITE_STATUS, EVENT, RESOURCES, COPILOT_APPLICATION_STATUS, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS, INVITE_SOURCE } from '../../constants';
89
import { PERMISSION } from '../../permissions/constants';
910

11+
1012
/**
1113
* API to update invite member to project.
1214
*
@@ -170,6 +172,79 @@ module.exports = [
170172
}, {
171173
transaction: t,
172174
});
175+
} else if (source === INVITE_SOURCE.WORK_MANAGER) {
176+
const allCopilotRequestsByProjectId = await models.CopilotRequest.findAll({
177+
where: {
178+
projectId: invite.projectId,
179+
},
180+
transaction: t,
181+
});
182+
183+
const requestIds = allCopilotRequestsByProjectId.map(item => item.id);
184+
185+
await models.CopilotRequest.update({
186+
status: COPILOT_REQUEST_STATUS.CANCELED,
187+
}, {
188+
where: {
189+
id: {
190+
[Op.in]: requestIds,
191+
}
192+
},
193+
transaction: t,
194+
});
195+
196+
const allCopilotOpportunityByRequestIds = await models.CopilotOpportunity.findAll({
197+
where: {
198+
copilotRequestId: {
199+
[Op.in]: requestIds,
200+
},
201+
},
202+
transaction: t,
203+
});
204+
205+
await models.CopilotOpportunity.update({
206+
status: COPILOT_OPPORTUNITY_STATUS.CANCELED,
207+
}, {
208+
where: {
209+
id: {
210+
[Op.in]: allCopilotOpportunityByRequestIds.map(item => item.id),
211+
},
212+
},
213+
transaction: t,
214+
});
215+
216+
const copilotApplications = await models.CopilotApplication.findAll({
217+
where: {
218+
opportunityId: {
219+
[Op.in]: allCopilotOpportunityByRequestIds.map(item => item.id),
220+
},
221+
},
222+
transaction: t,
223+
});
224+
225+
await models.CopilotApplication.update({
226+
status: COPILOT_APPLICATION_STATUS.CANCELED,
227+
}, {
228+
where: {
229+
id: {
230+
[Op.in]: copilotApplications.map(item => item.id),
231+
},
232+
},
233+
transaction: t,
234+
});
235+
236+
// Cancel the existing invites which are opened via
237+
// applications
238+
await models.ProjectMemberInvite.update({
239+
status: INVITE_STATUS.CANCELED,
240+
}, {
241+
where: {
242+
applicationId: {
243+
[Op.in]: copilotApplications.map(item => item.id),
244+
}
245+
},
246+
transaction: t,
247+
});
173248
}
174249

175250
await t.commit();

0 commit comments

Comments
 (0)