Skip to content

Commit cb54d3a

Browse files
committed
fixes
1 parent bcd7929 commit cb54d3a

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

src/models/eventsFactory.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ class EventsFactory extends Factory {
288288
if (result && result.events) {
289289
result.events.forEach(event => {
290290
event.projectId = this.projectId;
291+
event.firstAppearanceTimestamp = event.timestamp;
291292
});
292293
}
293294

@@ -400,14 +401,14 @@ class EventsFactory extends Factory {
400401
*
401402
* @todo move to Repetitions(?) model
402403
*/
403-
async getEventRepetitions(eventId, limit = 10, cursor = undefined) {
404+
async getEventRepetitions(eventId, limit = 10, cursor = null) {
404405
limit = this.validateLimit(limit);
405406

406-
cursor = cursor ? new ObjectID(cursor) : undefined;
407+
cursor = cursor ? new ObjectID(cursor) : null;
407408

408409
const result = {
409410
repetitions: [],
410-
cursor: undefined,
411+
cursor: null,
411412
};
412413

413414
/**
@@ -449,7 +450,7 @@ class EventsFactory extends Factory {
449450
const repetitions = await this.getCollection(this.TYPES.REPETITIONS)
450451
.find({
451452
groupHash: eventOriginal.groupHash,
452-
_id: cursor ? { $lte: cursor } : {},
453+
_id: cursor ? { $lte: cursor } : { $exists: true },
453454
})
454455
.sort({ _id: -1 })
455456
.limit(limit + 1)
@@ -466,10 +467,11 @@ class EventsFactory extends Factory {
466467
payload: composeFullRepetitionEvent(eventOriginal, repetition).payload,
467468
timestamp: repetition.timestamp,
468469
firstAppearanceTimestamp: eventOriginal.timestamp,
470+
projectId: this.projectId,
469471
});
470472
}
471473

472-
const isLastPortion = repetitions.length < limit;
474+
const isLastPortion = result.cursor === null;
473475

474476
/**
475477
* For last portion:
@@ -483,6 +485,7 @@ class EventsFactory extends Factory {
483485
const firstRepetition = {
484486
...eventOriginal,
485487
firstAppearanceTimestamp: eventOriginal.timestamp,
488+
projectId: this.projectId,
486489
};
487490

488491
result.repetitions.push(firstRepetition);
@@ -521,7 +524,10 @@ class EventsFactory extends Factory {
521524
};
522525
}
523526

524-
const originalEvent = await this.findById(repetition.eventId);
527+
const originalEvent = await this.getCollection(this.TYPES.EVENTS)
528+
.findOne({
529+
groupHash: repetition.groupHash,
530+
});
525531

526532
if (!originalEvent) {
527533
return null;
@@ -578,7 +584,7 @@ class EventsFactory extends Factory {
578584

579585
eventOriginal = await this.getCollection(this.TYPES.EVENTS)
580586
.findOne({
581-
_id: repetition.eventId,
587+
groupHash: repetition.groupHash,
582588
});
583589

584590
if (!eventOriginal) {
@@ -623,7 +629,7 @@ class EventsFactory extends Factory {
623629

624630
event = await this.getCollection(this.TYPES.EVENTS)
625631
.findOne({
626-
_id: repetition.eventId,
632+
groupHash: repetition.groupHash,
627633
});
628634

629635
if (!event) {
@@ -664,10 +670,10 @@ class EventsFactory extends Factory {
664670
if (repetition) {
665671
event = await this.getCollection(this.TYPES.EVENTS)
666672
.findOne({
667-
_id: repetition.eventId,
673+
groupHash: repetition.groupHash,
668674
});
669675

670-
query._id = new ObjectID(repetition.eventId);
676+
query._id = new ObjectID(event._id);
671677
}
672678
}
673679

@@ -736,10 +742,10 @@ class EventsFactory extends Factory {
736742
if (repetition) {
737743
event = await this.getCollection(this.TYPES.EVENTS)
738744
.findOne({
739-
_id: repetition.eventId,
745+
groupHash: repetition.groupHash,
740746
});
741747

742-
query._id = new ObjectID(repetition.eventId);
748+
query._id = new ObjectID(event._id);
743749
}
744750
}
745751

src/typeDefs/event.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ type EventMarks {
195195
ignored: Boolean!
196196
}
197197
198+
"""
199+
Object returned in repetitions property of event object
200+
"""
201+
type RepetitionsResponse {
202+
repetitions: [Event!]
203+
cursor: String
204+
}
205+
198206
"""
199207
Type representing Hawk single Event
200208
"""
@@ -234,6 +242,11 @@ type Event {
234242
"""
235243
timestamp: Float!
236244
245+
"""
246+
Event first appearance timestamp
247+
"""
248+
firstAppearanceTimestamp: Float!
249+
237250
"""
238251
Release data
239252
"""
@@ -242,7 +255,7 @@ type Event {
242255
"""
243256
Event repetitions
244257
"""
245-
repetitions(cursor: ID = null, limit: Int = 10): [Event!]
258+
repetitions(cursor: String = null, limit: Int = 10): RepetitionsResponse!
246259
247260
"""
248261
Array of users who visited event
@@ -401,8 +414,15 @@ extend type Mutation {
401414
Mutation marks event as visited for current user
402415
"""
403416
visitEvent(
404-
project: ID!
405-
id: ID!
417+
"""
418+
ID of project event is related to
419+
"""
420+
projectId: ID!
421+
422+
"""
423+
ID of the event to visit
424+
"""
425+
eventId: ID!
406426
): Boolean! @requireAuth
407427
408428
"""

0 commit comments

Comments
 (0)