@@ -288,6 +288,7 @@ class EventsFactory extends Factory {
288288 if ( result && result . events ) {
289289 result . events . forEach ( event => {
290290 event . projectId = this . projectId ;
291+ event . firstAppearanceTimestamp = event . timestamp ;
291292 } ) ;
292293 }
293294
@@ -400,14 +401,14 @@ class EventsFactory extends Factory {
400401 *
401402 * @todo move to Repetitions(?) model
402403 */
403- async getEventRepetitions ( eventId , limit = 10 , cursor = undefined ) {
404+ async getEventRepetitions ( eventId , limit = 10 , cursor = null ) {
404405 limit = this . validateLimit ( limit ) ;
405406
406- cursor = cursor ? new ObjectID ( cursor ) : undefined ;
407+ cursor = cursor ? new ObjectID ( cursor ) : null ;
407408
408409 const result = {
409410 repetitions : [ ] ,
410- cursor : undefined ,
411+ cursor : null ,
411412 } ;
412413
413414 /**
@@ -449,7 +450,7 @@ class EventsFactory extends Factory {
449450 const repetitions = await this . getCollection ( this . TYPES . REPETITIONS )
450451 . find ( {
451452 groupHash : eventOriginal . groupHash ,
452- _id : cursor ? { $lte : cursor } : { } ,
453+ _id : cursor ? { $lte : cursor } : { $exists : true } ,
453454 } )
454455 . sort ( { _id : - 1 } )
455456 . limit ( limit + 1 )
@@ -466,10 +467,11 @@ class EventsFactory extends Factory {
466467 payload : composeFullRepetitionEvent ( eventOriginal , repetition ) . payload ,
467468 timestamp : repetition . timestamp ,
468469 firstAppearanceTimestamp : eventOriginal . timestamp ,
470+ projectId : this . projectId ,
469471 } ) ;
470472 }
471473
472- const isLastPortion = repetitions . length < limit ;
474+ const isLastPortion = result . cursor === null ;
473475
474476 /**
475477 * For last portion:
@@ -483,6 +485,7 @@ class EventsFactory extends Factory {
483485 const firstRepetition = {
484486 ...eventOriginal ,
485487 firstAppearanceTimestamp : eventOriginal . timestamp ,
488+ projectId : this . projectId ,
486489 } ;
487490
488491 result . repetitions . push ( firstRepetition ) ;
@@ -521,7 +524,10 @@ class EventsFactory extends Factory {
521524 } ;
522525 }
523526
524- const originalEvent = await this . findById ( repetition . eventId ) ;
527+ const originalEvent = await this . getCollection ( this . TYPES . EVENTS )
528+ . findOne ( {
529+ groupHash : repetition . groupHash ,
530+ } ) ;
525531
526532 if ( ! originalEvent ) {
527533 return null ;
@@ -578,7 +584,7 @@ class EventsFactory extends Factory {
578584
579585 eventOriginal = await this . getCollection ( this . TYPES . EVENTS )
580586 . findOne ( {
581- _id : repetition . eventId ,
587+ groupHash : repetition . groupHash ,
582588 } ) ;
583589
584590 if ( ! eventOriginal ) {
@@ -623,7 +629,7 @@ class EventsFactory extends Factory {
623629
624630 event = await this . getCollection ( this . TYPES . EVENTS )
625631 . findOne ( {
626- _id : repetition . eventId ,
632+ groupHash : repetition . groupHash ,
627633 } ) ;
628634
629635 if ( ! event ) {
@@ -664,10 +670,10 @@ class EventsFactory extends Factory {
664670 if ( repetition ) {
665671 event = await this . getCollection ( this . TYPES . EVENTS )
666672 . findOne ( {
667- _id : repetition . eventId ,
673+ groupHash : repetition . groupHash ,
668674 } ) ;
669675
670- query . _id = new ObjectID ( repetition . eventId ) ;
676+ query . _id = new ObjectID ( event . _id ) ;
671677 }
672678 }
673679
@@ -736,10 +742,10 @@ class EventsFactory extends Factory {
736742 if ( repetition ) {
737743 event = await this . getCollection ( this . TYPES . EVENTS )
738744 . findOne ( {
739- _id : repetition . eventId ,
745+ groupHash : repetition . groupHash ,
740746 } ) ;
741747
742- query . _id = new ObjectID ( repetition . eventId ) ;
748+ query . _id = new ObjectID ( event . _id ) ;
743749 }
744750 }
745751
0 commit comments