Skip to content

Commit b1d7b40

Browse files
committed
cancel invites on canceling the copilot opportunity
1 parent 82dee4e commit b1d7b40

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/routes/copilotOpportunity/delete.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import _ from 'lodash';
2+
import { Op } from 'sequelize';
23

34
import models from '../../models';
45
import util from '../../util';
5-
import { COPILOT_APPLICATION_STATUS, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS } from '../../constants';
6+
import { COPILOT_APPLICATION_STATUS, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS, EVENT, INVITE_STATUS, RESOURCES } from '../../constants';
67
import { PERMISSION } from '../../permissions/constants';
78

9+
810
module.exports = [
911
(req, res, next) => {
1012
if (!util.hasPermissionByReq(PERMISSION.CANCEL_COPILOT_OPPORTUNITY, req)) {
@@ -54,6 +56,14 @@ module.exports = [
5456
}));
5557
});
5658

59+
const allInvites = await models.ProjectMemberInvite.findAll({
60+
where: {
61+
applicationId: {
62+
[Op.in]: applications.map(item => item.id),
63+
},
64+
},
65+
});
66+
5767
await Promise.all(promises);
5868

5969
await copilotRequest.update({
@@ -68,6 +78,21 @@ module.exports = [
6878
transaction,
6979
});
7080

81+
// update all the existing invites which are
82+
// associated to the copilot opportunity
83+
// with cancel status
84+
for (const invite of allInvites) {
85+
await invite.update({
86+
status: INVITE_STATUS.CANCELED,
87+
});
88+
await invite.reload();
89+
util.sendResourceToKafkaBus(
90+
req,
91+
EVENT.ROUTING_KEY.PROJECT_MEMBER_INVITE_UPDATED,
92+
RESOURCES.PROJECT_MEMBER_INVITE,
93+
invite.toJSON());
94+
}
95+
7196
res.status(200).send({ id: opportunity.id });
7297
})
7398

0 commit comments

Comments
 (0)