diff --git a/.circleci/config.yml b/.circleci/config.yml index 1acd4a4c..3fc9e254 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -149,7 +149,7 @@ workflows: context : org-global filters: branches: - only: ['develop', 'migration-setup'] + only: ['develop', 'migration-setup', 'pm-1168_2'] - deployProd: context : org-global filters: diff --git a/src/constants.js b/src/constants.js index 93326428..e9362976 100644 --- a/src/constants.js +++ b/src/constants.js @@ -15,7 +15,7 @@ export const COPILOT_REQUEST_STATUS = { REJECTED: 'rejected', SEEKING: 'seeking', CANCELED: 'canceled', - FULFILLED: 'fulfiled', + FULFILLED: 'fulfilled', }; export const COPILOT_APPLICATION_STATUS = { diff --git a/src/models/projectMemberInvite.js b/src/models/projectMemberInvite.js index dcae4cce..29bd895c 100644 --- a/src/models/projectMemberInvite.js +++ b/src/models/projectMemberInvite.js @@ -65,6 +65,14 @@ module.exports = function defineProjectMemberInvite(sequelize, DataTypes) { raw: true, }); + ProjectMemberInvite.getPendingInvitesForApplication = applicationId => ProjectMemberInvite.findAll({ + where: { + applicationId, + status: INVITE_STATUS.PENDING, + }, + raw: true, + }); + ProjectMemberInvite.getPendingAndReguestedInvitesForProject = projectId => ProjectMemberInvite.findAll({ where: { projectId, diff --git a/src/routes/copilotOpportunity/assign.js b/src/routes/copilotOpportunity/assign.js index 46cb6c78..ba066191 100644 --- a/src/routes/copilotOpportunity/assign.js +++ b/src/routes/copilotOpportunity/assign.js @@ -48,7 +48,7 @@ module.exports = [ } const application = await models.CopilotApplication.findOne({ - where: { id: applicationId }, + where: { id: applicationId, opportunityId: copilotOpportunityId }, transaction: t, }); @@ -99,6 +99,7 @@ module.exports = [ } const applicationUser = await util.getMemberDetailsByUserIds([userId], req.log, req.id); + req.log.info(applicationUser, 'applicationUser asdsd', userId); const invite = await models.ProjectMemberInvite.create({ status: INVITE_STATUS.PENDING, diff --git a/src/routes/projectMemberInvites/delete.js b/src/routes/projectMemberInvites/delete.js index d8c8be91..6eab2167 100644 --- a/src/routes/projectMemberInvites/delete.js +++ b/src/routes/projectMemberInvites/delete.js @@ -2,7 +2,7 @@ import _ from 'lodash'; import { middleware as tcMiddleware } from 'tc-core-library-js'; import models from '../../models'; import util from '../../util'; -import { PROJECT_MEMBER_ROLE, INVITE_STATUS, EVENT, RESOURCES } from '../../constants'; +import { PROJECT_MEMBER_ROLE, INVITE_STATUS, EVENT, RESOURCES, COPILOT_APPLICATION_STATUS } from '../../constants'; import { PERMISSION } from '../../permissions/constants'; /** @@ -74,7 +74,7 @@ module.exports = [ .update({ status: INVITE_STATUS.CANCELED, }) - .then((updatedInvite) => { + .then(async (updatedInvite) => { // emit the event util.sendResourceToKafkaBus( req, @@ -82,6 +82,23 @@ module.exports = [ RESOURCES.PROJECT_MEMBER_INVITE, updatedInvite.toJSON()); + // update the application if the invite + // originated from copilot opportunity + if (invite.applicationId) { + const allPendingInvitesForApplication = await models.ProjectMemberInvite.getPendingInvitesForApplication(invite.applicationId); + // If only the current invite is the open one's + // then the application status has to be moved to pending status + if (allPendingInvitesForApplication.length === 0) { + await models.CopilotApplication.update({ + status: COPILOT_APPLICATION_STATUS.PENDING, + }, { + where: { + id: invite.applicationId, + }, + }); + } + } + res.status(204).end(); }); }) diff --git a/src/routes/projectMemberInvites/update.js b/src/routes/projectMemberInvites/update.js index 438b722e..71d2a47d 100644 --- a/src/routes/projectMemberInvites/update.js +++ b/src/routes/projectMemberInvites/update.js @@ -81,7 +81,7 @@ module.exports = [ .update({ status: newStatus, }) - .then((updatedInvite) => { + .then(async (updatedInvite) => { // emit the event util.sendResourceToKafkaBus( req, @@ -166,6 +166,23 @@ module.exports = [ return next(e); } }); + } else if (updatedInvite.status === INVITE_STATUS.REFUSED) { + // update the application if the invite + // originated from copilot opportunity + if (updatedInvite.applicationId) { + const allPendingInvitesForApplication = await models.ProjectMemberInvite.getPendingInvitesForApplication(invite.applicationId); + // If only the current invite is the open one's + // then the application status has to be moved to pending status + if (allPendingInvitesForApplication.length === 0) { + await models.CopilotApplication.update({ + status: COPILOT_APPLICATION_STATUS.PENDING, + }, { + where: { + id: updatedInvite.applicationId, + }, + }); + } + } } return res.json(util.postProcessInvites('$.email', updatedInvite, req)); });