@@ -436,12 +436,13 @@ class EventsFactory extends Factory {
436436 * Returns Event repetitions
437437 *
438438 * @param {string|ObjectID } eventId - Event's id, could be repetitionId in case when we want to get repetitions portion by one repetition
439+ * @param {string|ObjectID } originalEventId - id of the original event
439440 * @param {Number } limit - count limitations
440441 * @param {Number } cursor - pointer to the next repetition
441442 *
442443 * @return {EventRepetitionsPortionSchema }
443444 */
444- async getEventRepetitions ( eventId , limit = 10 , cursor = null ) {
445+ async getEventRepetitions ( eventId , originalEventId , limit = 10 , cursor = null ) {
445446 limit = this . validateLimit ( limit ) ;
446447
447448 cursor = cursor ? new ObjectID ( cursor ) : null ;
@@ -455,21 +456,28 @@ class EventsFactory extends Factory {
455456 * Get original event
456457 * @type {Event }
457458 */
458- const eventOriginal = await this . findById ( eventId ) ;
459+ const eventOriginal = await this . findById ( originalEventId ) ;
459460
460461 if ( ! eventOriginal ) {
461- throw new Error ( `Original event not found for ${ eventId } ` ) ;
462+ throw new Error ( `Original event not found for ${ originalEventId } ` ) ;
463+ }
464+
465+ /**
466+ * Get portion based on cursor if cursor is not null
467+ */
468+ const query = cursor ? {
469+ groupHash : eventOriginal . groupHash ,
470+ _id : { $lte : cursor } ,
471+ } : {
472+ groupHash : eventOriginal . groupHash ,
462473 }
463474
464475 /**
465476 * Collect repetitions
466477 * @type {EventRepetitionSchema[] }
467478 */
468479 const repetitions = await this . getCollection ( this . TYPES . REPETITIONS )
469- . find ( {
470- groupHash : eventOriginal . groupHash ,
471- _id : cursor ? { $lte : cursor } : { } ,
472- } )
480+ . find ( query )
473481 . sort ( { _id : - 1 } )
474482 . limit ( limit + 1 )
475483 . toArray ( ) ;
0 commit comments