@@ -395,7 +395,7 @@ class EventsFactory extends Factory {
395395 *
396396 * @param {string|ObjectID } eventId - Event's id (may be repetition id)
397397 * @param {Number } limit - count limitations
398- * @param {Number } cursor - selection offset
398+ * @param {Number } cursor - pointer to the next repetition
399399 *
400400 * @return {EventRepetitionSchema[] }
401401 *
@@ -658,31 +658,32 @@ class EventsFactory extends Factory {
658658 * @returns {Promise<Event|null> } original event or null if not found
659659 */
660660 async _findOriginalEvent ( eventId ) {
661- let eventOriginal = await this . getCollection ( this . TYPES . EVENTS )
661+ let originalEvent ;
662+
663+ /**
664+ * Try to find it by repetitionId
665+ */
666+ const repetition = await this . getCollection ( this . TYPES . REPETITIONS )
662667 . findOne ( {
663668 _id : new ObjectID ( eventId ) ,
664669 } ) ;
665670
666671 /**
667- * If event is not found, try to find it as repetition
672+ * If repetition is not found by eventId , try to find it by eventId
668673 */
669- if ( ! eventOriginal ) {
670- const repetition = await this . getCollection ( this . TYPES . REPETITIONS )
674+ if ( ! repetition ) {
675+ originalEvent = await this . getCollection ( this . TYPES . EVENTS )
671676 . findOne ( {
672677 _id : new ObjectID ( eventId ) ,
673678 } ) ;
674-
675- if ( ! repetition ) {
676- return null ;
677- }
678-
679- eventOriginal = await this . getCollection ( this . TYPES . EVENTS )
679+ } else {
680+ originalEvent = await this . getCollection ( this . TYPES . EVENTS )
680681 . findOne ( {
681682 groupHash : repetition . groupHash ,
682683 } ) ;
683684 }
684685
685- return eventOriginal ;
686+ return originalEvent ;
686687 }
687688
688689 /**
0 commit comments