Skip to content

Commit a507bb9

Browse files
committed
fixes
1 parent ada2a24 commit a507bb9

3 files changed

Lines changed: 24 additions & 15 deletions

File tree

src/models/eventsFactory.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/**

src/typeDefs/event.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ type Event {
253253
release: Release
254254
255255
"""
256-
Event repetitions
256+
Event repetitions portion
257257
"""
258-
repetitions(cursor: String = null, limit: Int = 10): RepetitionsPortion!
258+
repetitionsPortion(cursor: String = null, limit: Int = 10): RepetitionsPortion!
259259
260260
"""
261261
Array of users who visited event

test/utils/merge.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ describe('composeEventPayloadWithRepetition', () => {
206206
});
207207

208208
it('should preserve original value when repetition payload has null', () => {
209+
210+
const originalEventPayload = {
211+
title: 'Original message',
212+
type: 'error',
213+
addons: JSON.stringify({ userId: 123 }),
214+
context: JSON.stringify({ sessionId: 'abc' }),
215+
};
216+
209217
/**
210218
* Arrange
211219
*/
@@ -222,7 +230,7 @@ describe('composeEventPayloadWithRepetition', () => {
222230
/**
223231
* Act
224232
*/
225-
const result = composeEventPayloadWithRepetition(mockOriginalEvent.payload, repetition);
233+
const result = composeEventPayloadWithRepetition(originalEventPayload, repetition);
226234

227235
/**
228236
* Assert

0 commit comments

Comments
 (0)