11import _ from 'lodash' ;
2+ import { Op } from 'sequelize' ;
23
34import models from '../../models' ;
45import util from '../../util' ;
5- import { COPILOT_APPLICATION_STATUS , COPILOT_OPPORTUNITY_STATUS , COPILOT_REQUEST_STATUS } from '../../constants' ;
6+ import { COPILOT_APPLICATION_STATUS , COPILOT_OPPORTUNITY_STATUS , COPILOT_REQUEST_STATUS , EVENT , INVITE_STATUS , RESOURCES } from '../../constants' ;
67import { PERMISSION } from '../../permissions/constants' ;
78
9+
810module . exports = [
911 ( req , res , next ) => {
1012 if ( ! util . hasPermissionByReq ( PERMISSION . CANCEL_COPILOT_OPPORTUNITY , req ) ) {
@@ -54,6 +56,14 @@ module.exports = [
5456 } ) ) ;
5557 } ) ;
5658
59+ const allInvites = await models . ProjectMemberInvite . findAll ( {
60+ where : {
61+ applicationId : {
62+ [ Op . in ] : applications . map ( item => item . id ) ,
63+ } ,
64+ } ,
65+ } ) ;
66+
5767 await Promise . all ( promises ) ;
5868
5969 await copilotRequest . update ( {
@@ -68,6 +78,21 @@ module.exports = [
6878 transaction,
6979 } ) ;
7080
81+ // update all the existing invites which are
82+ // associated to the copilot opportunity
83+ // with cancel status
84+ for ( const invite of allInvites ) {
85+ await invite . update ( {
86+ status : INVITE_STATUS . CANCELED ,
87+ } ) ;
88+ await invite . reload ( ) ;
89+ util . sendResourceToKafkaBus (
90+ req ,
91+ EVENT . ROUTING_KEY . PROJECT_MEMBER_INVITE_UPDATED ,
92+ RESOURCES . PROJECT_MEMBER_INVITE ,
93+ invite . toJSON ( ) ) ;
94+ }
95+
7196 res . status ( 200 ) . send ( { id : opportunity . id } ) ;
7297 } )
7398
0 commit comments