@@ -474,10 +474,22 @@ module.exports = (app, logger) => {
474
474
* @param {Object } original the original milestone
475
475
* @param {Object } updated the updated milestone
476
476
* @param {Object } project the project
477
+ * @param {Object } timeline the updated timeline
477
478
* @returns {Promise<void> } void
478
479
*/
479
- function sendMilestoneNotification ( req , original , updated , project ) {
480
+ function sendMilestoneNotification ( req , original , updated , project , timeline ) {
480
481
logger . debug ( 'sendMilestoneNotification' , original , updated ) ;
482
+ // throw generic milestone updated bus api event
483
+ createEvent ( BUS_API_EVENT . MILESTONE_UPDATED , {
484
+ projectId : project . id ,
485
+ projectName : project . name ,
486
+ projectUrl : connectProjectUrl ( project . id ) ,
487
+ timeline,
488
+ originalMilestone : original ,
489
+ updatedMilestone : updated ,
490
+ userId : req . authUser . userId ,
491
+ initiatorUserId : req . authUser . userId ,
492
+ } , logger ) ;
481
493
// Send transition events
482
494
if ( original . status !== updated . status ) {
483
495
let event ;
@@ -492,8 +504,7 @@ module.exports = (app, logger) => {
492
504
projectId : project . id ,
493
505
projectName : project . name ,
494
506
projectUrl : connectProjectUrl ( project . id ) ,
495
- timelineId : req . timeline . id ,
496
- timelineName : req . timeline . name ,
507
+ timeline,
497
508
originalMilestone : original ,
498
509
updatedMilestone : updated ,
499
510
userId : req . authUser . userId ,
@@ -510,8 +521,7 @@ module.exports = (app, logger) => {
510
521
projectId : project . id ,
511
522
projectName : project . name ,
512
523
projectUrl : connectProjectUrl ( project . id ) ,
513
- timelineId : req . timeline . id ,
514
- timelineName : req . timeline . name ,
524
+ timeline,
515
525
originalMilestone : original ,
516
526
updatedMilestone : updated ,
517
527
userId : req . authUser . userId ,
@@ -533,15 +543,16 @@ module.exports = (app, logger) => {
533
543
} )
534
544
. then ( ( project ) => {
535
545
if ( project ) {
536
- createEvent ( BUS_API_EVENT . PROJECT_PLAN_UPDATED , {
546
+ createEvent ( BUS_API_EVENT . MILESTONE_ADDED , {
537
547
projectId,
538
548
projectName : project . name ,
539
549
projectUrl : connectProjectUrl ( projectId ) ,
550
+ addedMilestone : created ,
540
551
userId : req . authUser . userId ,
541
552
initiatorUserId : req . authUser . userId ,
542
553
} , logger ) ;
543
554
}
544
- sendMilestoneNotification ( req , { } , created , project ) ;
555
+ // sendMilestoneNotification(req, {}, created, project);
545
556
} )
546
557
. catch ( err => null ) ; // eslint-disable-line no-unused-vars
547
558
} ) ;
@@ -551,60 +562,54 @@ module.exports = (app, logger) => {
551
562
*/
552
563
// eslint-disable-next-line no-unused-vars
553
564
app . on ( EVENT . ROUTING_KEY . MILESTONE_UPDATED , ( { req, original, updated, cascadedUpdates } ) => {
554
- logger . debug ( ' receive MILESTONE_UPDATED event' ) ;
565
+ logger . debug ( ` receive MILESTONE_UPDATED event for milestone ${ original . id } ` ) ;
555
566
556
567
const projectId = _ . parseInt ( req . params . projectId ) ;
568
+ const timeline = _ . omit ( req . timeline . toJSON ( ) , 'deletedAt' , 'deletedBy' ) ;
557
569
558
570
models . Project . findOne ( {
559
571
where : { id : projectId } ,
560
572
} )
561
- . then ( ( project ) => {
562
- // send PROJECT_UPDATED Kafka message when one of the specified below properties changed
563
- const watchProperties = [ 'startDate' , 'endDate' , 'duration' , 'details' , 'status' , 'order' ] ;
564
- if ( ! _ . isEqual ( _ . pick ( original , watchProperties ) ,
565
- _ . pick ( updated , watchProperties ) ) ) {
566
- createEvent ( BUS_API_EVENT . PROJECT_PLAN_UPDATED , {
567
- projectId,
568
- projectName : project . name ,
569
- projectUrl : connectProjectUrl ( projectId ) ,
570
- userId : req . authUser . userId ,
571
- initiatorUserId : req . authUser . userId ,
572
- } , logger ) ;
573
- }
574
- sendMilestoneNotification ( req , original , updated , project ) ;
573
+ . then ( ( project ) => {
574
+ logger . debug ( `Found project with id ${ projectId } ` ) ;
575
+ return models . Milestone . getTimelineDuration ( timeline . id )
576
+ . then ( ( { duration, progress } ) => {
577
+ timeline . duration = duration ;
578
+ timeline . progress = progress ;
579
+ sendMilestoneNotification ( req , original , updated , project , timeline ) ;
575
580
576
581
logger . debug ( 'cascadedUpdates' , cascadedUpdates ) ;
577
582
if ( cascadedUpdates && cascadedUpdates . milestones && cascadedUpdates . milestones . length > 0 ) {
578
583
_ . each ( cascadedUpdates . milestones , cascadedUpdate =>
579
- sendMilestoneNotification ( req , cascadedUpdate . original , cascadedUpdate . updated , project ) ,
584
+ sendMilestoneNotification ( req , cascadedUpdate . original , cascadedUpdate . updated , project , timeline ) ,
580
585
) ;
581
586
}
582
587
583
588
// if timeline is modified
584
589
if ( cascadedUpdates && cascadedUpdates . timeline ) {
585
- const timeline = cascadedUpdates . timeline ;
586
- // if endDate of the timeline is modified, raise TIMELINE_MODIFIED event
587
- if ( timeline . original . endDate !== timeline . updated . endDate ) {
590
+ const cTimeline = cascadedUpdates . timeline ;
591
+ // if endDate of the timeline is modified, raise TIMELINE_ADJUSTED event
592
+ if ( cTimeline . original . endDate !== cTimeline . updated . endDate ) {
588
593
// Raise Timeline changed event
589
- createEvent ( BUS_API_EVENT . TIMELINE_MODIFIED , {
594
+ createEvent ( BUS_API_EVENT . TIMELINE_ADJUSTED , {
590
595
projectId : project . id ,
591
596
projectName : project . name ,
592
597
projectUrl : connectProjectUrl ( project . id ) ,
593
- original : timeline . original ,
594
- updated : timeline . updated ,
598
+ originalTimeline : cTimeline . original ,
599
+ updatedTimeline : cTimeline . updated ,
595
600
userId : req . authUser . userId ,
596
601
initiatorUserId : req . authUser . userId ,
597
602
} , logger ) ;
598
603
}
599
604
}
600
- } )
601
- . catch ( err => null ) ; // eslint-disable-line no-unused-vars
605
+ } ) ;
606
+ } ) . catch ( err => null ) ; // eslint-disable-line no-unused-vars
602
607
} ) ;
603
608
604
609
/**
605
610
* MILESTONE_REMOVED.
606
611
*/
607
- app . on ( EVENT . ROUTING_KEY . MILESTONE_REMOVED , ( { req } ) => {
612
+ app . on ( EVENT . ROUTING_KEY . MILESTONE_REMOVED , ( { req, deleted } ) => {
608
613
logger . debug ( 'receive MILESTONE_REMOVED event' ) ;
609
614
// req.params.projectId is set by validateTimelineIdParam middleware
610
615
const projectId = _ . parseInt ( req . params . projectId ) ;
@@ -614,10 +619,11 @@ module.exports = (app, logger) => {
614
619
} )
615
620
. then ( ( project ) => {
616
621
if ( project ) {
617
- createEvent ( BUS_API_EVENT . PROJECT_PLAN_UPDATED , {
622
+ createEvent ( BUS_API_EVENT . MILESTONE_REMOVED , {
618
623
projectId,
619
624
projectName : project . name ,
620
625
projectUrl : connectProjectUrl ( projectId ) ,
626
+ removedMilestone : deleted ,
621
627
userId : req . authUser . userId ,
622
628
initiatorUserId : req . authUser . userId ,
623
629
} , logger ) ;
@@ -639,10 +645,12 @@ module.exports = (app, logger) => {
639
645
} )
640
646
. then ( ( project ) => {
641
647
if ( project ) {
642
- createEvent ( BUS_API_EVENT . PROJECT_PLAN_UPDATED , {
648
+ createEvent ( BUS_API_EVENT . TIMELINE_ADJUSTED , {
643
649
projectId,
644
650
projectName : project . name ,
645
651
projectUrl : connectProjectUrl ( projectId ) ,
652
+ originalTimeline : original ,
653
+ updatedTimeline : updated ,
646
654
userId : req . authUser . userId ,
647
655
initiatorUserId : req . authUser . userId ,
648
656
} , logger ) ;
0 commit comments