From a282f0b7f82289c01efd35463bf07366d79338b4 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Tue, 3 Jun 2025 16:57:41 +0200 Subject: [PATCH 1/8] fix: cancel all copilot requests for a project when manually copilot is added --- src/routes/projectMemberInvites/update.js | 52 +++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/routes/projectMemberInvites/update.js b/src/routes/projectMemberInvites/update.js index 9dfbfdf0..ccba79cf 100644 --- a/src/routes/projectMemberInvites/update.js +++ b/src/routes/projectMemberInvites/update.js @@ -6,6 +6,7 @@ import models from '../../models'; import util from '../../util'; import { INVITE_STATUS, EVENT, RESOURCES, COPILOT_APPLICATION_STATUS, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS, INVITE_SOURCE } from '../../constants'; import { PERMISSION } from '../../permissions/constants'; +import { Op } from 'sequelize'; /** * API to update invite member to project. @@ -170,6 +171,57 @@ module.exports = [ }, { transaction: t, }); + } else { + const allCopilotRequestsByProjectId = await models.CopilotRequest.findAll({ + where: { + projectId: invite.projectId, + }, + transaction: t, + }); + + const requestIds = allCopilotRequestsByProjectId.map(item => item.id); + + await models.CopilotRequest.update({ + status: COPILOT_REQUEST_STATUS.CANCELED, + }, { + where: { + id: { + [Op.in]: requestIds, + } + }, + transaction: t, + }); + + const allCopilotOpportunityByRequestIds = await models.CopilotOpportunity.findAll({ + where: { + copilotRequestId: { + [Op.in]: requestIds, + }, + }, + transaction: t, + }); + + await models.CopilotOpportunity.update({ + status: COPILOT_OPPORTUNITY_STATUS.CANCELED, + }, { + where: { + copilotRequestId: { + [Op.in]: allCopilotOpportunityByRequestIds, + }, + }, + transaction: t, + }); + + await models.CopilotApplication.update({ + status: COPILOT_APPLICATION_STATUS.CANCELED, + }, { + where: { + opportunityId: { + [Op.in]: allCopilotOpportunityByRequestIds.map(item => item.id), + }, + }, + transaction: t, + }); } await t.commit(); From ff6f62a4adfa0f3addeaef2ff159723db7ab5bbe Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Tue, 3 Jun 2025 16:58:00 +0200 Subject: [PATCH 2/8] fix: cancel all copilot requests for a project when manually copilot is added --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 753c7b1e..d3aab5b3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -149,7 +149,7 @@ workflows: context : org-global filters: branches: - only: ['develop', 'migration-setup', 'pm-1169'] + only: ['develop', 'migration-setup', 'pm-1169_1'] - deployProd: context : org-global filters: From 0a3317aaaa46b7fd257d9de97a1761b395111f3b Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Tue, 3 Jun 2025 17:02:11 +0200 Subject: [PATCH 3/8] fix: cancel all copilot requests for a project when manually copilot is added --- src/routes/projectMemberInvites/update.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/projectMemberInvites/update.js b/src/routes/projectMemberInvites/update.js index ccba79cf..864b9bd2 100644 --- a/src/routes/projectMemberInvites/update.js +++ b/src/routes/projectMemberInvites/update.js @@ -171,7 +171,7 @@ module.exports = [ }, { transaction: t, }); - } else { + } else if (source === INVITE_SOURCE.WORK_MANAGER) { const allCopilotRequestsByProjectId = await models.CopilotRequest.findAll({ where: { projectId: invite.projectId, From aa5cc622913aa9896541c23f7cc77fd62e5177e2 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Tue, 3 Jun 2025 17:03:08 +0200 Subject: [PATCH 4/8] fix: cancel all copilot requests for a project when manually copilot is added --- src/routes/projectMemberInvites/update.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/routes/projectMemberInvites/update.js b/src/routes/projectMemberInvites/update.js index 864b9bd2..88137695 100644 --- a/src/routes/projectMemberInvites/update.js +++ b/src/routes/projectMemberInvites/update.js @@ -1,12 +1,13 @@ import validate from 'express-validation'; import _ from 'lodash'; import Joi from 'joi'; +import { Op } from 'sequelize'; import { middleware as tcMiddleware } from 'tc-core-library-js'; import models from '../../models'; import util from '../../util'; import { INVITE_STATUS, EVENT, RESOURCES, COPILOT_APPLICATION_STATUS, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS, INVITE_SOURCE } from '../../constants'; import { PERMISSION } from '../../permissions/constants'; -import { Op } from 'sequelize'; + /** * API to update invite member to project. From f7579a00b45ab5a1fae40bb748b68d0c412ce76b Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Tue, 3 Jun 2025 22:53:05 +0200 Subject: [PATCH 5/8] fix: cancel all copilot requests for a project when manually copilot is added --- src/routes/projectMemberInvites/update.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/routes/projectMemberInvites/update.js b/src/routes/projectMemberInvites/update.js index 88137695..37f4731b 100644 --- a/src/routes/projectMemberInvites/update.js +++ b/src/routes/projectMemberInvites/update.js @@ -173,6 +173,7 @@ module.exports = [ transaction: t, }); } else if (source === INVITE_SOURCE.WORK_MANAGER) { + req.log.info("cancelling all existing requests", source); const allCopilotRequestsByProjectId = await models.CopilotRequest.findAll({ where: { projectId: invite.projectId, @@ -181,6 +182,7 @@ module.exports = [ }); const requestIds = allCopilotRequestsByProjectId.map(item => item.id); + req.log.info("requestIds", requestIds); await models.CopilotRequest.update({ status: COPILOT_REQUEST_STATUS.CANCELED, @@ -193,6 +195,8 @@ module.exports = [ transaction: t, }); + req.log.info("updated copilot request"); + const allCopilotOpportunityByRequestIds = await models.CopilotOpportunity.findAll({ where: { copilotRequestId: { @@ -202,6 +206,8 @@ module.exports = [ transaction: t, }); + req.log.info("allCopilotOpportunityByRequestIds", allCopilotOpportunityByRequestIds.length); + await models.CopilotOpportunity.update({ status: COPILOT_OPPORTUNITY_STATUS.CANCELED, }, { @@ -213,6 +219,8 @@ module.exports = [ transaction: t, }); + req.log.info("updated copilot opportunity"); + await models.CopilotApplication.update({ status: COPILOT_APPLICATION_STATUS.CANCELED, }, { @@ -223,6 +231,8 @@ module.exports = [ }, transaction: t, }); + + req.log.info("updated CopilotApplication"); } await t.commit(); From 206547869f894812776e5f8fde84b8f33a89066b Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Tue, 3 Jun 2025 23:45:16 +0200 Subject: [PATCH 6/8] fix: cancel all copilot requests for a project when manually copilot is added --- src/routes/projectMemberInvites/update.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/projectMemberInvites/update.js b/src/routes/projectMemberInvites/update.js index 37f4731b..843c82be 100644 --- a/src/routes/projectMemberInvites/update.js +++ b/src/routes/projectMemberInvites/update.js @@ -212,8 +212,8 @@ module.exports = [ status: COPILOT_OPPORTUNITY_STATUS.CANCELED, }, { where: { - copilotRequestId: { - [Op.in]: allCopilotOpportunityByRequestIds, + id: { + [Op.in]: allCopilotOpportunityByRequestIds.map(item => item.id), }, }, transaction: t, From 724d0281f2ee910eeba14ea601986b786f09703e Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Wed, 4 Jun 2025 00:12:27 +0200 Subject: [PATCH 7/8] fix: cancel all copilot requests for a project when manually copilot is added --- src/routes/projectMemberInvites/update.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/routes/projectMemberInvites/update.js b/src/routes/projectMemberInvites/update.js index 843c82be..3c3d71be 100644 --- a/src/routes/projectMemberInvites/update.js +++ b/src/routes/projectMemberInvites/update.js @@ -173,7 +173,6 @@ module.exports = [ transaction: t, }); } else if (source === INVITE_SOURCE.WORK_MANAGER) { - req.log.info("cancelling all existing requests", source); const allCopilotRequestsByProjectId = await models.CopilotRequest.findAll({ where: { projectId: invite.projectId, @@ -182,7 +181,6 @@ module.exports = [ }); const requestIds = allCopilotRequestsByProjectId.map(item => item.id); - req.log.info("requestIds", requestIds); await models.CopilotRequest.update({ status: COPILOT_REQUEST_STATUS.CANCELED, @@ -195,8 +193,6 @@ module.exports = [ transaction: t, }); - req.log.info("updated copilot request"); - const allCopilotOpportunityByRequestIds = await models.CopilotOpportunity.findAll({ where: { copilotRequestId: { @@ -206,8 +202,6 @@ module.exports = [ transaction: t, }); - req.log.info("allCopilotOpportunityByRequestIds", allCopilotOpportunityByRequestIds.length); - await models.CopilotOpportunity.update({ status: COPILOT_OPPORTUNITY_STATUS.CANCELED, }, { @@ -219,8 +213,6 @@ module.exports = [ transaction: t, }); - req.log.info("updated copilot opportunity"); - await models.CopilotApplication.update({ status: COPILOT_APPLICATION_STATUS.CANCELED, }, { @@ -231,8 +223,6 @@ module.exports = [ }, transaction: t, }); - - req.log.info("updated CopilotApplication"); } await t.commit(); From 21b079bbf5fd9f2d7980288b24322a35f5f4d828 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Wed, 4 Jun 2025 00:57:12 +0200 Subject: [PATCH 8/8] fix: cancel all copilot requests for a project when manually copilot is added --- src/routes/projectMemberInvites/update.js | 26 +++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/routes/projectMemberInvites/update.js b/src/routes/projectMemberInvites/update.js index 3c3d71be..7869f7e3 100644 --- a/src/routes/projectMemberInvites/update.js +++ b/src/routes/projectMemberInvites/update.js @@ -213,16 +213,38 @@ module.exports = [ transaction: t, }); + const copilotApplications = await models.CopilotApplication.findAll({ + where: { + opportunityId: { + [Op.in]: allCopilotOpportunityByRequestIds.map(item => item.id), + }, + }, + transaction: t, + }); + await models.CopilotApplication.update({ status: COPILOT_APPLICATION_STATUS.CANCELED, }, { where: { - opportunityId: { - [Op.in]: allCopilotOpportunityByRequestIds.map(item => item.id), + id: { + [Op.in]: copilotApplications.map(item => item.id), }, }, transaction: t, }); + + // Cancel the existing invites which are opened via + // applications + await models.ProjectMemberInvite.update({ + status: INVITE_STATUS.CANCELED, + }, { + where: { + applicationId: { + [Op.in]: copilotApplications.map(item => item.id), + } + }, + transaction: t, + }); } await t.commit();