Skip to content

Commit 0aa318d

Browse files
committed
fix(): fix visitedBy issue
1 parent cbe8876 commit 0aa318d

4 files changed

Lines changed: 34 additions & 26 deletions

File tree

src/models/eventsFactory.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,27 @@ class EventsFactory extends Factory {
299299
lastEvent = result.pop();
300300
}
301301

302+
const composedResult = result.map(dailyEvent => {
303+
const repetition = dailyEvent.repetition;
304+
const event = dailyEvent.event;
305+
306+
console.log('current projectId is ', this.projectId);
307+
308+
return {
309+
...dailyEvent,
310+
id: dailyEvent._id.toString(),
311+
_id: undefined,
312+
event: this._composeEventWithRepetition(event, repetition),
313+
repetition: undefined,
314+
}
315+
})
316+
317+
console.log('result', composedResult)
318+
302319

303320
return {
304321
nextCursor: lastEvent ? lastEvent._id.toString() : null,
305-
dailyEvents: result,
322+
dailyEvents: composedResult,
306323
};
307324
}
308325

@@ -679,6 +696,8 @@ class EventsFactory extends Factory {
679696
_id: new ObjectID(eventId),
680697
});
681698

699+
console.log('repetition found', repetition)
700+
682701
/**
683702
* If repetition is not found by eventId, try to find it by eventId
684703
*/
@@ -687,11 +706,15 @@ class EventsFactory extends Factory {
687706
.findOne({
688707
_id: new ObjectID(eventId),
689708
});
709+
710+
console.log('no repetition found, fetched by original event id', originalEvent);
690711
} else {
691712
originalEvent = await this.getCollection(this.TYPES.EVENTS)
692713
.findOne({
693714
groupHash: repetition.groupHash,
694715
});
716+
717+
console.log('repetition found, fetched by groupHash', originalEvent);
695718
}
696719

697720
return originalEvent;
@@ -711,6 +734,7 @@ class EventsFactory extends Factory {
711734
firstAppearanceTimestamp: event.timestamp,
712735
timestamp: repetition.timestamp,
713736
payload: composeEventPayloadWithRepetition(event.payload, repetition),
737+
projectId: this.projectId,
714738
};
715739
}
716740
}

src/resolvers/event.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ module.exports = {
112112
* Mark event as visited for current user
113113
*
114114
* @param {ResolverObj} _obj - resolver context
115-
* @param {string} project - project id
116-
* @param {string} id - event id
115+
* @param {string} projectId - project id
116+
* @param {string} eventId - event id
117117
* @param {UserInContext} user - user context
118118
* @return {Promise<boolean>}
119119
*/
120-
async visitEvent(_obj, { project, id }, { user }) {
121-
const factory = new EventsFactory(project);
120+
async visitEvent(_obj, { projectId, eventId }, { user }) {
121+
const factory = new EventsFactory(projectId);
122122

123-
const { result } = await factory.visitEvent(id, user.id);
123+
const { result } = await factory.visitEvent(eventId, user.id);
124124

125125
return !!result.ok;
126126
},

src/resolvers/project.js

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const EventsFactory = require('../models/eventsFactory');
88
const ProjectToWorkspace = require('../models/projectToWorkspace');
99
const { dateFromObjectId } = require('../utils/dates');
1010
const ProjectModel = require('../models/project').default;
11-
const { composeFullRepetitionEvent } = require('../utils/merge');
11+
const { composeEventPayloadWithRepetition } = require('../utils/merge');
1212

1313
const EVENTS_GROUP_HASH_INDEX_NAME = 'groupHashUnique';
1414
const REPETITIONS_GROUP_HASH_INDEX_NAME = 'groupHash_hashed';
@@ -356,25 +356,9 @@ module.exports = {
356356

357357
const dailyEventsPortion = await factory.findRecentDailyEventsWithEventAndRepetition(limit, nextCursor, sort, filters, search);
358358

359-
dailyEventsPortion.dailyEvents.forEach((dailyEvent) => {
360-
const dailyEventLatestRepetition = dailyEvent.repetition;
361-
const dailyEventOriginalEvent = dailyEvent.event;
359+
console.log('daily events portion composed, ...[event]', dailyEventsPortion);
362360

363-
const mergedRepetition = composeFullRepetitionEvent(dailyEventOriginalEvent, dailyEventLatestRepetition);
364-
const stringifiedId = dailyEvent._id.toString();
365-
mergedRepetition.firstAppearanceTimestamp = dailyEvent.event.timestamp;
366-
367-
delete dailyEvent.repetition;
368-
delete dailyEvent.event;
369-
delete dailyEvent._id;
370-
371-
dailyEvent.event = mergedRepetition;
372-
dailyEvent.id = stringifiedId;
373-
374-
return dailyEvent;
375-
})
376-
377-
console.log('daily events portion composed, ...[event]', dailyEventsPortion.dailyEvents[0].event);
361+
// this.dailyEventsPortion.dailyEvents.forEach(dailyEvent)
378362

379363
return dailyEventsPortion;
380364
},

src/typeDefs/event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type Release {
5353
"""
5454
Release commits
5555
"""
56-
commits: [Commit!]!
56+
commits: [Commit]
5757
}
5858
5959
"""

0 commit comments

Comments
 (0)