Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ workflows:
context : org-global
filters:
branches:
only: ['develop', 'migration-setup', 'PM-1314']
only: ['develop', 'migration-setup', 'pm-1398']
- deployProd:
context : org-global
filters:
Expand Down
6 changes: 3 additions & 3 deletions src/routes/copilotRequest/approveRequest.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import moment from 'moment';
import { Op } from 'sequelize';

import models from '../../models';
import { CONNECT_NOTIFICATION_EVENT, COPILOT_REQUEST_STATUS, TEMPLATE_IDS, USER_ROLE } from '../../constants';
import { CONNECT_NOTIFICATION_EVENT, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS, TEMPLATE_IDS, USER_ROLE } from '../../constants';
import util from '../../util';
import { createEvent } from '../../services/busApi';
import { getCopilotTypeLabel } from '../../utils/copilot';
Expand Down Expand Up @@ -46,13 +46,13 @@ module.exports = (req, data, existingTransaction) => {
projectId,
type: data.type,
status: {
[Op.notIn]: [COPILOT_REQUEST_STATUS.CANCELED],
[Op.in]: [COPILOT_OPPORTUNITY_STATUS.ACTIVE],
}
},
})
.then((existingCopilotOpportunityOfSameType) => {
if (existingCopilotOpportunityOfSameType) {
const err = new Error('There\'s an opportunity of same type already!');
const err = new Error('There\'s an active opportunity of same type already!');
_.assign(err, {
status: 403,
});
Expand Down
27 changes: 26 additions & 1 deletion src/routes/projectMemberInvites/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = [

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

// Check if the copilot opportunity is still active
// When the invited user tries to accept the invite
if (invite.applicationId) {
req.log.debug(`Invite from copilot application: ${invite.applicationId}`);
const application = await models.CopilotApplication.findOne({
where: {
id: invite.applicationId,
}
});

const opportunity = await models.CopilotOpportunity.findOne({
where: {
id: application.opportunityId,
},
});

req.log.debug(`Copilot opportunity status: ${opportunity.status}`);
if (opportunity.status !== COPILOT_OPPORTUNITY_STATUS.ACTIVE) {
req.log.debug(`Copilot opportunity status is not active`);
const err = new Error('The copilot opportunity is not in active status');
err.status = 409;
return next(err);
}
}

req.log.debug('Updating invite status');
return invite
.update({
Expand Down