@@ -149,7 +149,7 @@ class EventsFactory extends Factory {
149149 * Returns events that grouped by day
150150 *
151151 * @param {Number } limit - events count limitations
152- * @param {String } paginatoinCursor - pointer to the first daily event to be selected
152+ * @param {String } paginationCursor - pointer to the first daily event to be selected
153153 * @param {'BY_DATE' | 'BY_COUNT' } sort - events sort order
154154 * @param {EventsFilters } filters - marks by which events should be filtered
155155 * @param {String } search - Search query
@@ -158,7 +158,7 @@ class EventsFactory extends Factory {
158158 */
159159 async findRecentDailyEventsWithEventAndRepetition (
160160 limit = 10 ,
161- paginationCursor = '' ,
161+ paginationCursor = null ,
162162 sort = 'BY_DATE' ,
163163 filters = { } ,
164164 search = ''
@@ -197,8 +197,8 @@ class EventsFactory extends Factory {
197197 {
198198 $match : paginationCursor ? {
199199 _id : {
200- $gte : new ObjectID ( paginationCursor ) ,
201- }
200+ $lte : new ObjectID ( paginationCursor ) ,
201+ } ,
202202 } : { } ,
203203 } ,
204204 {
@@ -266,7 +266,7 @@ class EventsFactory extends Factory {
266266 localField : 'lastRepetitionId' ,
267267 foreignField : '_id' ,
268268 as : 'repetition' ,
269- }
269+ } ,
270270 } ,
271271 /**
272272 * Desctruct event and repetition arrays since there are only one document in both arrays
@@ -293,32 +293,23 @@ class EventsFactory extends Factory {
293293
294294 const result = await cursor . toArray ( ) ;
295295
296- let lastEvent ;
297-
298- if ( result . length === limit + 1 ) {
299- lastEvent = result . pop ( ) ;
300- }
296+ const nextCursor = result . pop ( ) . _id ;
301297
302298 const composedResult = result . map ( dailyEvent => {
303299 const repetition = dailyEvent . repetition ;
304300 const event = dailyEvent . event ;
305301
306- console . log ( 'current projectId is ' , this . projectId ) ;
307-
308302 return {
309303 ...dailyEvent ,
310304 id : dailyEvent . _id . toString ( ) ,
311305 _id : undefined ,
312306 event : this . _composeEventWithRepetition ( event , repetition ) ,
313307 repetition : undefined ,
314- }
315- } )
316-
317- console . log ( 'result' , composedResult )
308+ } ;
309+ } ) ;
318310
319-
320311 return {
321- nextCursor : lastEvent ? lastEvent . _id . toString ( ) : null ,
312+ nextCursor : nextCursor ,
322313 dailyEvents : composedResult ,
323314 } ;
324315 }
@@ -696,7 +687,7 @@ class EventsFactory extends Factory {
696687 _id : new ObjectID ( eventId ) ,
697688 } ) ;
698689
699- console . log ( 'repetition found' , repetition )
690+ console . log ( 'repetition found' , repetition ) ;
700691
701692 /**
702693 * If repetition is not found by eventId, try to find it by eventId
@@ -707,14 +698,14 @@ class EventsFactory extends Factory {
707698 _id : new ObjectID ( eventId ) ,
708699 } ) ;
709700
710- console . log ( 'no repetition found, fetched by original event id' , originalEvent ) ;
701+ console . log ( 'no repetition found, fetched by original event id' , originalEvent ) ;
711702 } else {
712703 originalEvent = await this . getCollection ( this . TYPES . EVENTS )
713704 . findOne ( {
714705 groupHash : repetition . groupHash ,
715706 } ) ;
716707
717- console . log ( 'repetition found, fetched by groupHash' , originalEvent ) ;
708+ console . log ( 'repetition found, fetched by groupHash' , originalEvent ) ;
718709 }
719710
720711 return originalEvent ;
0 commit comments