11import { getMidnightWithTimezoneOffset , getUTCMidnight } from '../utils/dates' ;
2- import { composeFullRepetitionEvent } from '../utils/merge' ;
32import { groupBy } from '../utils/grouper' ;
43import safe from 'safe-regex' ;
54
@@ -423,14 +422,6 @@ class EventsFactory extends Factory {
423422 . skip ( skip )
424423 . toArray ( ) ;
425424
426- repetitions . forEach ( repetition => {
427- repetition . payload = composeFullRepetitionEvent ( eventOriginal , repetition ) . payload ;
428-
429- if ( 'delta' in repetition ) {
430- delete repetition . delta ;
431- }
432- } ) ;
433-
434425 const isLastPortion = repetitions . length < limit && skip === 0 ;
435426
436427 /**
@@ -464,30 +455,10 @@ class EventsFactory extends Factory {
464455 * @todo move to Repetitions(?) model
465456 */
466457 async getEventRepetition ( repetitionId ) {
467- const repetition = await this . getCollection ( this . TYPES . REPETITIONS )
458+ return this . getCollection ( this . TYPES . REPETITIONS )
468459 . findOne ( {
469- _id : ObjectID ( repetitionId ) ,
460+ _id : new ObjectID ( repetitionId ) ,
470461 } ) ;
471-
472- if ( ! repetition ) {
473- return null ;
474- }
475-
476- const event = await this . findOneByQuery ( {
477- groupHash : repetition . groupHash ,
478- } ) ;
479-
480- if ( ! event ) {
481- return null ;
482- }
483-
484- repetition . payload = composeFullRepetitionEvent ( event , repetition ) . payload ;
485-
486- if ( 'delta' in repetition ) {
487- delete repetition . delta ;
488- }
489-
490- return repetition ;
491462 }
492463
493464 /**
@@ -498,6 +469,10 @@ class EventsFactory extends Factory {
498469 async getEventLastRepetition ( eventId ) {
499470 const repetitions = await this . getEventRepetitions ( eventId , 1 ) ;
500471
472+ if ( repetitions . length === 0 ) {
473+ return null ;
474+ }
475+
501476 return repetitions . shift ( ) ;
502477 }
503478
0 commit comments