Skip to content

Commit f3d87ad

Browse files
committed
imp(): pass original event id to getEventRepetitions
1 parent e10a613 commit f3d87ad

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/models/eventsFactory.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,13 @@ class EventsFactory extends Factory {
436436
* Returns Event repetitions
437437
*
438438
* @param {string|ObjectID} eventId - Event's id, could be repetitionId in case when we want to get repetitions portion by one repetition
439+
* @param {string|ObjectID} originalEventId - id of the original event
439440
* @param {Number} limit - count limitations
440441
* @param {Number} cursor - pointer to the next repetition
441442
*
442443
* @return {EventRepetitionsPortionSchema}
443444
*/
444-
async getEventRepetitions(eventId, limit = 10, cursor = null) {
445+
async getEventRepetitions(eventId, originalEventId, limit = 10, cursor = null) {
445446
limit = this.validateLimit(limit);
446447

447448
cursor = cursor ? new ObjectID(cursor) : null;
@@ -455,21 +456,28 @@ class EventsFactory extends Factory {
455456
* Get original event
456457
* @type {Event}
457458
*/
458-
const eventOriginal = await this.findById(eventId);
459+
const eventOriginal = await this.findById(originalEventId);
459460

460461
if (!eventOriginal) {
461-
throw new Error(`Original event not found for ${eventId}`);
462+
throw new Error(`Original event not found for ${originalEventId}`);
463+
}
464+
465+
/**
466+
* Get portion based on cursor if cursor is not null
467+
*/
468+
const query = cursor ? {
469+
groupHash: eventOriginal.groupHash,
470+
_id: { $lte: cursor },
471+
} : {
472+
groupHash: eventOriginal.groupHash,
462473
}
463474

464475
/**
465476
* Collect repetitions
466477
* @type {EventRepetitionSchema[]}
467478
*/
468479
const repetitions = await this.getCollection(this.TYPES.REPETITIONS)
469-
.find({
470-
groupHash: eventOriginal.groupHash,
471-
_id: cursor ? { $lte: cursor } : {},
472-
})
480+
.find(query)
473481
.sort({ _id: -1 })
474482
.limit(limit + 1)
475483
.toArray();

src/resolvers/event.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ module.exports = {
2929
*
3030
* @return {RepetitionsPortion}
3131
*/
32-
async repetitionsPortion({ _id: eventId, projectId }, { limit, cursor }) {
32+
async repetitionsPortion({ _id: eventId, projectId, originalEventId }, { limit, cursor }) {
3333
const factory = new EventsFactory(projectId);
3434

35-
return factory.getEventRepetitions(eventId, limit, cursor);
35+
return factory.getEventRepetitions(eventId, originalEventId, limit, cursor);
3636
},
3737

3838
/**

0 commit comments

Comments
 (0)