@@ -91,25 +91,27 @@ module.exports = [
91
91
err . status = 400 ;
92
92
throw err ;
93
93
}
94
- return models . PhaseProduct . create ( data ) ;
95
- } )
94
+ return models . PhaseProduct . create ( data )
96
95
. then ( ( _newPhaseProduct ) => {
97
96
newPhaseProduct = _ . cloneDeep ( _newPhaseProduct ) ;
98
97
req . log . debug ( 'new phase product created (id# %d, name: %s)' ,
99
98
newPhaseProduct . id , newPhaseProduct . name ) ;
100
99
newPhaseProduct = newPhaseProduct . get ( { plain : true } ) ;
101
100
newPhaseProduct = _ . omit ( newPhaseProduct , [ 'deletedAt' , 'utm' ] ) ;
101
+ } ) ;
102
+ } ) )
103
+ . then ( ( ) => {
104
+ // Send events to buses
105
+ req . log . debug ( 'Sending event to RabbitMQ bus for phase product %d' , newPhaseProduct . id ) ;
106
+ req . app . services . pubsub . publish ( EVENT . ROUTING_KEY . PROJECT_PHASE_PRODUCT_ADDED ,
107
+ newPhaseProduct ,
108
+ { correlationId : req . id } ,
109
+ ) ;
110
+ req . log . debug ( 'Sending event to Kafka bus for phase product %d' , newPhaseProduct . id ) ;
111
+ req . app . emit ( EVENT . ROUTING_KEY . PROJECT_PHASE_PRODUCT_ADDED , { req, created : newPhaseProduct } ) ;
102
112
103
- // Send events to buses
104
- req . log . debug ( 'Sending event to RabbitMQ bus for phase product %d' , newPhaseProduct . id ) ;
105
- req . app . services . pubsub . publish ( EVENT . ROUTING_KEY . PROJECT_PHASE_PRODUCT_ADDED ,
106
- newPhaseProduct ,
107
- { correlationId : req . id } ,
108
- ) ;
109
- req . log . debug ( 'Sending event to Kafka bus for phase product %d' , newPhaseProduct . id ) ;
110
- req . app . emit ( EVENT . ROUTING_KEY . PROJECT_PHASE_PRODUCT_ADDED , { req, created : newPhaseProduct } ) ;
111
-
112
- res . status ( 201 ) . json ( util . wrapResponse ( req . id , newPhaseProduct , 1 , 201 ) ) ;
113
- } ) ) . catch ( ( err ) => { next ( err ) ; } ) ;
113
+ res . status ( 201 ) . json ( util . wrapResponse ( req . id , newPhaseProduct , 1 , 201 ) ) ;
114
+ } )
115
+ . catch ( ( err ) => { next ( err ) ; } ) ;
114
116
} ,
115
117
] ;
0 commit comments