@@ -8,6 +8,7 @@ const EventsFactory = require('../models/eventsFactory');
88const ProjectToWorkspace = require ( '../models/projectToWorkspace' ) ;
99const { dateFromObjectId } = require ( '../utils/dates' ) ;
1010const ProjectModel = require ( '../models/project' ) . default ;
11+ const { composeFullRepetitionEvent } = require ( '../utils/merge' ) ;
1112
1213const EVENTS_GROUP_HASH_INDEX_NAME = 'groupHashUnique' ;
1314const REPETITIONS_GROUP_HASH_INDEX_NAME = 'groupHash_hashed' ;
@@ -289,6 +290,7 @@ module.exports = {
289290 */
290291 async event ( project , { id : eventId } ) {
291292 const factory = new EventsFactory ( project . _id ) ;
293+
292294 const event = await factory . findById ( eventId ) ;
293295
294296 if ( ! event ) {
@@ -344,7 +346,7 @@ module.exports = {
344346 *
345347 * @return {Promise<RecentEventSchema[]> }
346348 */
347- async dailyEventsPortion ( project , { limit, skip , sort, filters, search } ) {
349+ async dailyEventsPortion ( project , { limit, cursor , sort, filters, search } ) {
348350 if ( search ) {
349351 if ( search . length > MAX_SEARCH_QUERY_LENGTH ) {
350352 search = search . slice ( 0 , MAX_SEARCH_QUERY_LENGTH ) ;
@@ -353,22 +355,29 @@ module.exports = {
353355
354356 const factory = new EventsFactory ( project . _id ) ;
355357
356- // @todo - rename
357- const res = factory . findRecentDailyEventsWithEventAndRepetition ( limit , skip , sort , filters , search ) ;
358+ const dailyEventsPortion = await factory . findRecentDailyEventsWithEventAndRepetition ( limit , cursor , sort , filters , search ) ;
358359
359- res . forEach ( ( dailyEvent ) => {
360+ dailyEventsPortion . dailyEvents . forEach ( ( dailyEvent ) => {
360361 const dailyEventLatestRepetition = dailyEvent . repetition ;
361362 const dailyEventOriginalEvent = dailyEvent . event ;
362363
363- // wait for util implementation
364- // const mergedRepetition = merge(dailyEventOriginalEvent, dailyEventLatestRepetition);
364+ const mergedRepetition = composeFullRepetitionEvent ( dailyEventOriginalEvent , dailyEventLatestRepetition ) ;
365+ const stringifiedId = dailyEvent . _id . toString ( ) ;
366+
367+
365368 delete dailyEvent . repetition ;
366369 delete dailyEvent . event ;
367-
368- // dailyEvent.event = mergedRepetition;
370+ delete dailyEvent . _id ;
371+
372+ dailyEvent . event = mergedRepetition ;
373+ dailyEvent . id = stringifiedId ;
369374
370375 return dailyEvent ;
371376 } )
377+
378+ console . log ( 'daily events portion composed, ...[event]' , dailyEventsPortion ) ;
379+
380+ return dailyEventsPortion ;
372381 } ,
373382
374383 /**
0 commit comments