Skip to content

Commit 8082112

Browse files
committed
fix: dont allow invite when opportunity is closed
1 parent 8587a8e commit 8082112

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/routes/copilotRequest/approveRequest.service.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import moment from 'moment';
44
import { Op } from 'sequelize';
55

66
import models from '../../models';
7-
import { CONNECT_NOTIFICATION_EVENT, COPILOT_REQUEST_STATUS, TEMPLATE_IDS, USER_ROLE } from '../../constants';
7+
import { CONNECT_NOTIFICATION_EVENT, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS, TEMPLATE_IDS, USER_ROLE } from '../../constants';
88
import util from '../../util';
99
import { createEvent } from '../../services/busApi';
1010
import { getCopilotTypeLabel } from '../../utils/copilot';
@@ -46,13 +46,13 @@ module.exports = (req, data, existingTransaction) => {
4646
projectId,
4747
type: data.type,
4848
status: {
49-
[Op.notIn]: [COPILOT_REQUEST_STATUS.CANCELED],
49+
[Op.in]: [COPILOT_OPPORTUNITY_STATUS.ACTIVE],
5050
}
5151
},
5252
})
5353
.then((existingCopilotOpportunityOfSameType) => {
5454
if (existingCopilotOpportunityOfSameType) {
55-
const err = new Error('There\'s an opportunity of same type already!');
55+
const err = new Error('There\'s an active opportunity of same type already!');
5656
_.assign(err, {
5757
status: 403,
5858
});

src/routes/projectMemberInvites/update.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module.exports = [
5050

5151
// get invite by id and project id
5252
return models.ProjectMemberInvite.getPendingOrRequestedProjectInviteById(projectId, inviteId)
53-
.then((invite) => {
53+
.then(async (invite) => {
5454
// if invite doesn't exist, return 404
5555
if (!invite) {
5656
const err = new Error(`invite not found for project id ${projectId}, inviteId ${inviteId},` +
@@ -85,6 +85,31 @@ module.exports = [
8585
return next(err);
8686
}
8787

88+
// Check if the copilot opportunity is still active
89+
// When the invited user tries to accept the invite
90+
if (invite.applicationId) {
91+
req.log.debug(`Invite from copilot application: ${invite.applicationId}`);
92+
const application = await models.CopilotApplication.findOne({
93+
where: {
94+
id: invite.applicationId,
95+
}
96+
});
97+
98+
const opportunity = await models.CopilotOpportunity.findOne({
99+
where: {
100+
id: application.opportunityId,
101+
},
102+
});
103+
104+
req.log.debug(`Copilot opportunity status: ${opportunity.status}`);
105+
if (opportunity.status !== COPILOT_OPPORTUNITY_STATUS.ACTIVE) {
106+
req.log.debug(`Copilot opportunity status is not active`);
107+
const err = new Error('The copilot opportunity is not in active status');
108+
err.status = 409;
109+
return next(err);
110+
}
111+
}
112+
88113
req.log.debug('Updating invite status');
89114
return invite
90115
.update({

0 commit comments

Comments
 (0)