From d6bd47e6b08c66a26d7103f3ae72c251280bbd6d Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Fri, 23 May 2025 20:14:42 +0200 Subject: [PATCH 01/12] fix: QA feedbacks for assigning copilots --- .circleci/config.yml | 2 +- src/constants.js | 2 +- src/routes/copilotOpportunity/assign.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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/routes/copilotOpportunity/assign.js b/src/routes/copilotOpportunity/assign.js index 46cb6c78..31c35697 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, }); From 07973aa8577d0495a3ee90489e7e3130a592a0f0 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Fri, 23 May 2025 20:31:28 +0200 Subject: [PATCH 02/12] fix: move application to pending when all invites are rejected --- src/models/projectMemberInvite.js | 8 ++++++++ src/routes/projectMemberInvites/delete.js | 22 ++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) 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/projectMemberInvites/delete.js b/src/routes/projectMemberInvites/delete.js index d8c8be91..5bc2e30d 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,24 @@ 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.Sequelize.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 === 1) { + await models.Sequelize.CopilotApplication.update({ + status: COPILOT_APPLICATION_STATUS.PENDING, + }, { + where: { + id: invite.applicationId, + }, + }); + } + } + res.status(204).end(); }); }) From c43ace7810f6da025140af99c33ef3c33a5227b6 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Fri, 23 May 2025 20:33:08 +0200 Subject: [PATCH 03/12] fix: move application to pending when all invites are rejected --- src/routes/projectMemberInvites/delete.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/routes/projectMemberInvites/delete.js b/src/routes/projectMemberInvites/delete.js index 5bc2e30d..e6ef9f65 100644 --- a/src/routes/projectMemberInvites/delete.js +++ b/src/routes/projectMemberInvites/delete.js @@ -85,8 +85,10 @@ module.exports = [ // update the application if the invite // originated from copilot opportunity if (invite.applicationId) { + req.log.info("Invite originated from the application id", invite.applicationId); const allPendingInvitesForApplication = await models.Sequelize.ProjectMemberInvite.getPendingInvitesForApplication(invite.applicationId); + req.log.info("All pending invites which are open", allPendingInvitesForApplication); // If only the current invite is the open one's // then the application status has to be moved to pending status if (allPendingInvitesForApplication.length === 1) { From 9ba2c671797210e604b7ec849f7af159c8662c7b Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Sat, 24 May 2025 00:36:14 +0200 Subject: [PATCH 04/12] fix: move application to pending when all invites are rejected --- src/routes/projectMemberInvites/update.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/routes/projectMemberInvites/update.js b/src/routes/projectMemberInvites/update.js index 438b722e..11821d18 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,26 @@ 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) { + req.log.info("Invite originated from the application id", invite.applicationId); + const allPendingInvitesForApplication = await models.Sequelize.ProjectMemberInvite.getPendingInvitesForApplication(invite.applicationId); + + req.log.info("All pending invites which are open", allPendingInvitesForApplication); + // If only the current invite is the open one's + // then the application status has to be moved to pending status + if (allPendingInvitesForApplication.length === 1) { + await models.Sequelize.CopilotApplication.update({ + status: COPILOT_APPLICATION_STATUS.PENDING, + }, { + where: { + id: updatedInvite.applicationId, + }, + }); + } + } } return res.json(util.postProcessInvites('$.email', updatedInvite, req)); }); From 4b1e2b38acef504dd57fb2355264e9d00eb6e2f3 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Sun, 25 May 2025 23:41:16 +0200 Subject: [PATCH 05/12] fix: move application to pending when all invites are rejected --- src/routes/projectMemberInvites/delete.js | 4 ++-- src/routes/projectMemberInvites/update.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/routes/projectMemberInvites/delete.js b/src/routes/projectMemberInvites/delete.js index e6ef9f65..5d50901b 100644 --- a/src/routes/projectMemberInvites/delete.js +++ b/src/routes/projectMemberInvites/delete.js @@ -86,13 +86,13 @@ module.exports = [ // originated from copilot opportunity if (invite.applicationId) { req.log.info("Invite originated from the application id", invite.applicationId); - const allPendingInvitesForApplication = await models.Sequelize.ProjectMemberInvite.getPendingInvitesForApplication(invite.applicationId); + const allPendingInvitesForApplication = await models.ProjectMemberInvite.getPendingInvitesForApplication(invite.applicationId); req.log.info("All pending invites which are open", allPendingInvitesForApplication); // If only the current invite is the open one's // then the application status has to be moved to pending status if (allPendingInvitesForApplication.length === 1) { - await models.Sequelize.CopilotApplication.update({ + await models.CopilotApplication.update({ status: COPILOT_APPLICATION_STATUS.PENDING, }, { where: { diff --git a/src/routes/projectMemberInvites/update.js b/src/routes/projectMemberInvites/update.js index 11821d18..651acc93 100644 --- a/src/routes/projectMemberInvites/update.js +++ b/src/routes/projectMemberInvites/update.js @@ -171,13 +171,13 @@ module.exports = [ // originated from copilot opportunity if (updatedInvite.applicationId) { req.log.info("Invite originated from the application id", invite.applicationId); - const allPendingInvitesForApplication = await models.Sequelize.ProjectMemberInvite.getPendingInvitesForApplication(invite.applicationId); + const allPendingInvitesForApplication = await models.ProjectMemberInvite.getPendingInvitesForApplication(invite.applicationId); req.log.info("All pending invites which are open", allPendingInvitesForApplication); // If only the current invite is the open one's // then the application status has to be moved to pending status if (allPendingInvitesForApplication.length === 1) { - await models.Sequelize.CopilotApplication.update({ + await models.CopilotApplication.update({ status: COPILOT_APPLICATION_STATUS.PENDING, }, { where: { From 4defcf7174d09fdee343f377670d957fbaa052c7 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Mon, 26 May 2025 00:10:18 +0200 Subject: [PATCH 06/12] fix: move application to pending when all invites are rejected --- 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 651acc93..6dade7c7 100644 --- a/src/routes/projectMemberInvites/update.js +++ b/src/routes/projectMemberInvites/update.js @@ -176,7 +176,7 @@ module.exports = [ req.log.info("All pending invites which are open", allPendingInvitesForApplication); // If only the current invite is the open one's // then the application status has to be moved to pending status - if (allPendingInvitesForApplication.length === 1) { + if (allPendingInvitesForApplication.length === 0) { await models.CopilotApplication.update({ status: COPILOT_APPLICATION_STATUS.PENDING, }, { From cc46a746046a1bcf669c0bc182c57a7e2ea8cddb Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Mon, 26 May 2025 00:11:08 +0200 Subject: [PATCH 07/12] fix: move application to pending when all invites are rejected --- src/routes/projectMemberInvites/delete.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/projectMemberInvites/delete.js b/src/routes/projectMemberInvites/delete.js index 5d50901b..dafe5938 100644 --- a/src/routes/projectMemberInvites/delete.js +++ b/src/routes/projectMemberInvites/delete.js @@ -91,7 +91,7 @@ module.exports = [ req.log.info("All pending invites which are open", allPendingInvitesForApplication); // If only the current invite is the open one's // then the application status has to be moved to pending status - if (allPendingInvitesForApplication.length === 1) { + if (allPendingInvitesForApplication.length === 0) { await models.CopilotApplication.update({ status: COPILOT_APPLICATION_STATUS.PENDING, }, { From 3bf61b2d1df82989c7cad2387e48414fbe9a0cbf Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Mon, 26 May 2025 00:37:16 +0200 Subject: [PATCH 08/12] fix: move application to pending when all invites are rejected --- src/routes/projectMemberInvites/delete.js | 3 --- src/routes/projectMemberInvites/update.js | 3 --- 2 files changed, 6 deletions(-) diff --git a/src/routes/projectMemberInvites/delete.js b/src/routes/projectMemberInvites/delete.js index dafe5938..6eab2167 100644 --- a/src/routes/projectMemberInvites/delete.js +++ b/src/routes/projectMemberInvites/delete.js @@ -85,10 +85,7 @@ module.exports = [ // update the application if the invite // originated from copilot opportunity if (invite.applicationId) { - req.log.info("Invite originated from the application id", invite.applicationId); const allPendingInvitesForApplication = await models.ProjectMemberInvite.getPendingInvitesForApplication(invite.applicationId); - - req.log.info("All pending invites which are open", allPendingInvitesForApplication); // 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) { diff --git a/src/routes/projectMemberInvites/update.js b/src/routes/projectMemberInvites/update.js index 6dade7c7..71d2a47d 100644 --- a/src/routes/projectMemberInvites/update.js +++ b/src/routes/projectMemberInvites/update.js @@ -170,10 +170,7 @@ module.exports = [ // update the application if the invite // originated from copilot opportunity if (updatedInvite.applicationId) { - req.log.info("Invite originated from the application id", invite.applicationId); const allPendingInvitesForApplication = await models.ProjectMemberInvite.getPendingInvitesForApplication(invite.applicationId); - - req.log.info("All pending invites which are open", allPendingInvitesForApplication); // 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) { From e19a9d1d49c2a468d59f10cc146c346d053d4724 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Mon, 26 May 2025 00:37:33 +0200 Subject: [PATCH 09/12] fix: move application to pending when all invites are rejected --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3fc9e254..1acd4a4c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -149,7 +149,7 @@ workflows: context : org-global filters: branches: - only: ['develop', 'migration-setup', 'pm-1168_2'] + only: ['develop', 'migration-setup'] - deployProd: context : org-global filters: From d4d37907b0444a851dc381a13ca2f5718cd236f9 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Mon, 26 May 2025 16:03:14 +0200 Subject: [PATCH 10/12] debug --- .circleci/config.yml | 2 +- src/routes/copilotOpportunity/assign.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) 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/routes/copilotOpportunity/assign.js b/src/routes/copilotOpportunity/assign.js index 31c35697..8244eedd 100644 --- a/src/routes/copilotOpportunity/assign.js +++ b/src/routes/copilotOpportunity/assign.js @@ -99,6 +99,7 @@ module.exports = [ } const applicationUser = await util.getMemberDetailsByUserIds([userId], req.log, req.id); + console.log(applicationUser, 'applicationUser'); const invite = await models.ProjectMemberInvite.create({ status: INVITE_STATUS.PENDING, From 3a8a1fc9c5bddddc82c584328c8d5395fec98cf7 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Mon, 26 May 2025 16:03:34 +0200 Subject: [PATCH 11/12] debug --- src/routes/copilotOpportunity/assign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/copilotOpportunity/assign.js b/src/routes/copilotOpportunity/assign.js index 8244eedd..01d797fa 100644 --- a/src/routes/copilotOpportunity/assign.js +++ b/src/routes/copilotOpportunity/assign.js @@ -99,7 +99,7 @@ module.exports = [ } const applicationUser = await util.getMemberDetailsByUserIds([userId], req.log, req.id); - console.log(applicationUser, 'applicationUser'); + req.log.info(applicationUser, 'applicationUser'); const invite = await models.ProjectMemberInvite.create({ status: INVITE_STATUS.PENDING, From ea2ac33b7eda8466104fb447553cb6484120c651 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Mon, 26 May 2025 16:55:54 +0200 Subject: [PATCH 12/12] debug --- src/routes/copilotOpportunity/assign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/copilotOpportunity/assign.js b/src/routes/copilotOpportunity/assign.js index 01d797fa..ba066191 100644 --- a/src/routes/copilotOpportunity/assign.js +++ b/src/routes/copilotOpportunity/assign.js @@ -99,7 +99,7 @@ module.exports = [ } const applicationUser = await util.getMemberDetailsByUserIds([userId], req.log, req.id); - req.log.info(applicationUser, 'applicationUser'); + req.log.info(applicationUser, 'applicationUser asdsd', userId); const invite = await models.ProjectMemberInvite.create({ status: INVITE_STATUS.PENDING,