From e54354faacfb2dbf43859a92c740b3df12b9fc4e Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Thu, 7 Aug 2025 22:42:39 +0200 Subject: [PATCH 1/6] feat: add directly to project --- src/routes/copilotOpportunity/assign.js | 63 +++++++++++-------------- 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/src/routes/copilotOpportunity/assign.js b/src/routes/copilotOpportunity/assign.js index 6cab3b55..16785954 100644 --- a/src/routes/copilotOpportunity/assign.js +++ b/src/routes/copilotOpportunity/assign.js @@ -6,10 +6,11 @@ import config from 'config'; import models from '../../models'; import util from '../../util'; import { PERMISSION } from '../../permissions/constants'; -import { CONNECT_NOTIFICATION_EVENT, COPILOT_APPLICATION_STATUS, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS, EVENT, INVITE_STATUS, PROJECT_MEMBER_ROLE, RESOURCES, TEMPLATE_IDS } from '../../constants'; +import { CONNECT_NOTIFICATION_EVENT, COPILOT_APPLICATION_STATUS, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS, EVENT, INVITE_STATUS, PROJECT_MEMBER_ROLE, RESOURCES, TEMPLATE_IDS, USER_ROLE } from '../../constants'; import { getCopilotTypeLabel } from '../../utils/copilot'; import { createEvent } from '../../services/busApi'; import moment from 'moment'; +import { Op } from 'sequelize'; const assignCopilotOpportunityValidations = { body: Joi.object().keys({ @@ -172,51 +173,41 @@ module.exports = [ return; } - const existingInvite = await models.ProjectMemberInvite.findAll({ - where: { - userId, - projectId, - role: PROJECT_MEMBER_ROLE.COPILOT, - status: INVITE_STATUS.PENDING, - }, - transaction: t, - }); - - if (existingInvite && existingInvite.length) { - const err = new Error(`User already has an pending invite to the project`); - err.status = 400; - throw err; - } - - const invite = await models.ProjectMemberInvite.create({ - status: INVITE_STATUS.PENDING, - role: PROJECT_MEMBER_ROLE.COPILOT, - userId, + const member = { projectId, - applicationId: application.id, + role: USER_ROLE.COPILOT, + userId, createdBy: req.authUser.userId, - createdAt: new Date(), updatedBy: req.authUser.userId, - updatedAt: new Date(), - }, { - transaction: t, - }) + }; - util.sendResourceToKafkaBus( - req, - EVENT.ROUTING_KEY.PROJECT_MEMBER_INVITE_CREATED, - RESOURCES.PROJECT_MEMBER_INVITE, - Object.assign({}, invite.toJSON(), { - source: 'copilot_portal', - }), - ); + await util.addUserToProject(req, member, t) await application.update({ - status: COPILOT_APPLICATION_STATUS.INVITED, + status: COPILOT_APPLICATION_STATUS.ACCEPTED, }, { transaction: t, }); + // Cancel other applications + const otherApplications = await models.CopilotApplication.findAll({ + where: { + opportunityId: copilotOpportunityId, + id: { + [Op.notIn]: [applicationId], + }, + }, + transaction: t, + }); + + for (const otherApplication of otherApplications) { + await otherApplication.update({ + status: COPILOT_APPLICATION_STATUS.CANCELED, + }, { + transaction: t, + }); + } + res.status(200).send({ id: applicationId }); }).catch(err => next(err)); }, From fc14edfb9ac4ba04d9b2b82418a7968d354d7af7 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Thu, 7 Aug 2025 22:42:58 +0200 Subject: [PATCH 2/6] feat: add directly to project --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b3f2600c..74e60a37 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -149,7 +149,7 @@ workflows: context : org-global filters: branches: - only: ['develop', 'migration-setup', 'pm-1398'] + only: ['develop', 'migration-setup', 'pm-1610'] - deployProd: context : org-global filters: From aa818745bf9f9e769ad777203c5bacf17cad6455 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Thu, 7 Aug 2025 23:04:27 +0200 Subject: [PATCH 3/6] feat: add directly to project --- 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 16785954..76e2c62a 100644 --- a/src/routes/copilotOpportunity/assign.js +++ b/src/routes/copilotOpportunity/assign.js @@ -180,7 +180,7 @@ module.exports = [ createdBy: req.authUser.userId, updatedBy: req.authUser.userId, }; - + req.context.currentProjectMembers = activeMembers; await util.addUserToProject(req, member, t) await application.update({ From b120f6cd99932d2f6ab5ce3b7144bac405efe9ac Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Thu, 7 Aug 2025 23:23:18 +0200 Subject: [PATCH 4/6] feat: add directly to project --- src/routes/copilotOpportunity/assign.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/routes/copilotOpportunity/assign.js b/src/routes/copilotOpportunity/assign.js index 76e2c62a..9bd4988c 100644 --- a/src/routes/copilotOpportunity/assign.js +++ b/src/routes/copilotOpportunity/assign.js @@ -180,6 +180,7 @@ module.exports = [ createdBy: req.authUser.userId, updatedBy: req.authUser.userId, }; + req.context = req.context || {}; req.context.currentProjectMembers = activeMembers; await util.addUserToProject(req, member, t) From 6b9eed93b70062bb2e7e1065329770ba98f29a02 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Fri, 8 Aug 2025 00:00:11 +0200 Subject: [PATCH 5/6] feat: add directly to project --- 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 9bd4988c..0312feb4 100644 --- a/src/routes/copilotOpportunity/assign.js +++ b/src/routes/copilotOpportunity/assign.js @@ -175,7 +175,7 @@ module.exports = [ const member = { projectId, - role: USER_ROLE.COPILOT, + role: USER_ROLE.TC_COPILOT, userId, createdBy: req.authUser.userId, updatedBy: req.authUser.userId, From e208bc19f7c54882c5d0ce215249985cc9250a8c Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Fri, 8 Aug 2025 00:26:47 +0200 Subject: [PATCH 6/6] fix: updated toast message --- src/routes/copilotOpportunity/assign.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/routes/copilotOpportunity/assign.js b/src/routes/copilotOpportunity/assign.js index 0312feb4..eabe9288 100644 --- a/src/routes/copilotOpportunity/assign.js +++ b/src/routes/copilotOpportunity/assign.js @@ -190,6 +190,19 @@ module.exports = [ transaction: t, }); + await opportunity.update({ + status: COPILOT_OPPORTUNITY_STATUS.COMPLETED, + }, { + transaction: t, + }); + + + await copilotRequest.update({ + status: COPILOT_REQUEST_STATUS.FULFILLED, + }, { + transaction: t, + }); + // Cancel other applications const otherApplications = await models.CopilotApplication.findAll({ where: {