- 
                Notifications
    
You must be signed in to change notification settings  - Fork 55
 
fix(PM-1169) Cancel all copilot requests when copilot added via WM #816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
a282f0b
              ff6f62a
              0a3317a
              aa5cc62
              f7579a0
              2065478
              724d028
              21b079b
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,12 +1,14 @@ | ||
| 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'; | ||
| 
     | 
||
| 
     | 
||
| /** | ||
| * API to update invite member to project. | ||
| * | ||
| 
          
            
          
           | 
    @@ -170,6 +172,67 @@ 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, | ||
| }, | ||
| transaction: t, | ||
| }); | ||
| 
     | 
||
| const requestIds = allCopilotRequestsByProjectId.map(item => item.id); | ||
| req.log.info("requestIds", requestIds); | ||
                
       | 
||
| 
     | 
||
| await models.CopilotRequest.update({ | ||
| status: COPILOT_REQUEST_STATUS.CANCELED, | ||
| }, { | ||
| where: { | ||
| id: { | ||
| [Op.in]: requestIds, | ||
| } | ||
| }, | ||
| transaction: t, | ||
| }); | ||
| 
     | 
||
| req.log.info("updated copilot request"); | ||
| 
     | 
||
| const allCopilotOpportunityByRequestIds = await models.CopilotOpportunity.findAll({ | ||
| where: { | ||
| copilotRequestId: { | ||
| [Op.in]: requestIds, | ||
| }, | ||
| }, | ||
| transaction: t, | ||
| }); | ||
| 
     | 
||
| req.log.info("allCopilotOpportunityByRequestIds", allCopilotOpportunityByRequestIds.length); | ||
                
       | 
||
| 
     | 
||
| await models.CopilotOpportunity.update({ | ||
| status: COPILOT_OPPORTUNITY_STATUS.CANCELED, | ||
| }, { | ||
| where: { | ||
| id: { | ||
| [Op.in]: allCopilotOpportunityByRequestIds.map(item => item.id), | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change from   | 
||
| }, | ||
| }, | ||
| transaction: t, | ||
| }); | ||
| 
     | 
||
| req.log.info("updated copilot opportunity"); | ||
| 
     | 
||
| await models.CopilotApplication.update({ | ||
| status: COPILOT_APPLICATION_STATUS.CANCELED, | ||
| }, { | ||
| where: { | ||
| opportunityId: { | ||
| [Op.in]: allCopilotOpportunityByRequestIds.map(item => item.id), | ||
| }, | ||
| }, | ||
| transaction: t, | ||
| }); | ||
| 
     | 
||
| req.log.info("updated CopilotApplication"); | ||
                
       | 
||
| } | ||
| 
     | 
||
| await t.commit(); | ||
| 
          
            
          
           | 
    ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The branch name has been changed from 'pm-1169' to 'pm-1169_1'. Ensure that this change is intentional and that all relevant documentation and references to the branch name are updated accordingly.