Skip to content

Commit 795acae

Browse files
committed
revert some types changes
1 parent 107567c commit 795acae

3 files changed

Lines changed: 147 additions & 34 deletions

File tree

src/models/eventsFactory.js

Lines changed: 127 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -392,15 +392,15 @@ class EventsFactory extends Factory {
392392
/**
393393
* Returns Event repetitions
394394
*
395-
* @param {string|ObjectID} groupHash - Event's group hash
395+
* @param {string|ObjectID} eventId - Event's id (may be repetition id)
396396
* @param {Number} limit - count limitations
397397
* @param {Number} cursor - selection offset
398398
*
399399
* @return {EventRepetitionSchema[]}
400400
*
401401
* @todo move to Repetitions(?) model
402402
*/
403-
async getEventRepetitionsByGroupHash(groupHash, limit = 10, cursor = undefined) {
403+
async getEventRepetitions(eventId, limit = 10, cursor = undefined) {
404404
limit = this.validateLimit(limit);
405405

406406
cursor = cursor ? new ObjectID(cursor) : undefined;
@@ -414,11 +414,30 @@ class EventsFactory extends Factory {
414414
* Get original event
415415
* @type {EventSchema}
416416
*/
417-
const eventOriginal = await this.getCollection(this.TYPES.EVENTS)
417+
let eventOriginal = await this.getCollection(this.TYPES.EVENTS)
418418
.findOne({
419-
groupHash: groupHash,
419+
_id: new ObjectID(eventId),
420420
});
421421

422+
/**
423+
* If event is not found, try to find it as repetition
424+
*/
425+
if (!eventOriginal) {
426+
const repetition = await this.getCollection(this.TYPES.REPETITIONS)
427+
.findOne({
428+
_id: new ObjectID(eventId),
429+
});
430+
431+
if (!repetition) {
432+
return result;
433+
}
434+
435+
eventOriginal = await this.getCollection(this.TYPES.EVENTS)
436+
.findOne({
437+
_id: repetition.eventId,
438+
});
439+
}
440+
422441
if (!eventOriginal) {
423442
return result;
424443
}
@@ -538,12 +557,35 @@ class EventsFactory extends Factory {
538557
* @param {string} groupHash - hash of event to get the release
539558
* @returns {Release|null}
540559
*/
541-
async getEventRelease(groupHash) {
560+
async getEventRelease(eventId) {
542561
const eventOriginal = await this.getCollection(this.TYPES.EVENTS)
543562
.findOne({
544-
groupHash: groupHash,
563+
_id: new ObjectID(eventId),
545564
});
546565

566+
/**
567+
* If event is not found, try to find it as repetition
568+
*/
569+
if (!eventOriginal) {
570+
const repetition = await this.getCollection(this.TYPES.REPETITIONS)
571+
.findOne({
572+
_id: new ObjectID(eventId),
573+
});
574+
575+
if (!repetition) {
576+
return null;
577+
}
578+
579+
eventOriginal = await this.getCollection(this.TYPES.EVENTS)
580+
.findOne({
581+
_id: repetition.eventId,
582+
});
583+
584+
if (!eventOriginal) {
585+
return null;
586+
}
587+
}
588+
547589
const release = await mongo.databases.events.collection(this.TYPES.RELEASES).findOne({
548590
release: eventOriginal.payload.release,
549591
projectId: this.projectId.toString(),
@@ -555,15 +597,43 @@ class EventsFactory extends Factory {
555597
/**
556598
* Mark event as visited for passed user
557599
*
558-
* @param {string|ObjectId} groupHash
600+
* @param {string|ObjectId} eventId
559601
* @param {string|ObjectId} userId
560602
*
561603
* @return {Promise<void>}
562604
*/
563-
async visitEvent(groupHash, userId) {
605+
async visitEvent(eventId, userId) {
606+
let event = await this.getCollection(this.TYPES.EVENTS)
607+
.findOne({
608+
_id: new ObjectID(eventId),
609+
});
610+
611+
/**
612+
* If event is not found, try to find it as repetition
613+
*/
614+
if (!event) {
615+
const repetition = await this.getCollection(this.TYPES.REPETITIONS)
616+
.findOne({
617+
_id: new ObjectID(eventId),
618+
});
619+
620+
if (!repetition) {
621+
return null;
622+
}
623+
624+
event = await this.getCollection(this.TYPES.EVENTS)
625+
.findOne({
626+
_id: repetition.eventId,
627+
});
628+
629+
if (!event) {
630+
return null;
631+
}
632+
}
633+
564634
return this.getCollection(this.TYPES.EVENTS)
565635
.updateOne(
566-
{ groupHash: groupHash },
636+
{ _id: new ObjectID(eventId) },
567637
{ $addToSet: { visitedBy: new ObjectID(userId) } }
568638
);
569639
}
@@ -576,11 +646,32 @@ class EventsFactory extends Factory {
576646
*
577647
* @return {Promise<void>}
578648
*/
579-
async toggleEventMark(groupHash, mark) {
649+
async toggleEventMark(eventId, mark) {
580650
const collection = this.getCollection(this.TYPES.EVENTS);
581-
const query = { groupHash: groupHash };
651+
const query = { _id: new ObjectID(eventId) };
582652

583653
const event = await collection.findOne(query);
654+
655+
656+
/**
657+
* If event is not found, try to find it as repetition
658+
*/
659+
if (!event) {
660+
const repetition = await this.getCollection(this.TYPES.REPETITIONS)
661+
.findOne({
662+
_id: new ObjectID(eventId),
663+
});
664+
665+
if (repetition) {
666+
event = await this.getCollection(this.TYPES.EVENTS)
667+
.findOne({
668+
_id: repetition.eventId,
669+
});
670+
671+
query._id = new ObjectID(repetition.eventId);
672+
}
673+
}
674+
584675
const markKey = `marks.${mark}`;
585676

586677
let update;
@@ -624,13 +715,35 @@ class EventsFactory extends Factory {
624715
/**
625716
* Update assignee to selected event
626717
*
627-
* @param {string} groupHash - event id
718+
* @param {string} eventId - event id
628719
* @param {string} assignee - assignee id for this event
629720
* @return {Promise<void>}
630721
*/
631-
async updateAssignee(groupHash, assignee) {
722+
async updateAssignee(eventId, assignee) {
632723
const collection = this.getCollection(this.TYPES.EVENTS);
633-
const query = { groupHash: groupHash };
724+
const query = { _id: new ObjectID(eventId) };
725+
726+
const event = await collection.findOne(query);
727+
728+
/**
729+
* If event is not found, try to find it as repetition
730+
*/
731+
if (!event) {
732+
const repetition = await this.getCollection(this.TYPES.REPETITIONS)
733+
.findOne({
734+
_id: new ObjectID(eventId),
735+
});
736+
737+
if (repetition) {
738+
event = await this.getCollection(this.TYPES.EVENTS)
739+
.findOne({
740+
_id: repetition.eventId,
741+
});
742+
743+
query._id = new ObjectID(repetition.eventId);
744+
}
745+
}
746+
634747
const update = {
635748
$set: { assignee: assignee },
636749
};

src/resolvers/event.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ module.exports = {
2626
* @param {String} eventId
2727
* @param {String} projectId
2828
* @param {Number} limit
29-
* @param {Number} skip
29+
* @param {Number} cursor
3030
*
3131
* @return {EventRepetitionSchema[]}
3232
*/
33-
async repetitions({ groupHash, projectId }, { limit, skip }) {
33+
async repetitions({ _id: eventId, projectId }, { limit, cursor }) {
3434
const factory = new EventsFactory(projectId);
3535

36-
return factory.getEventRepetitions(groupHash, limit, skip);
36+
return factory.getEventRepetitions(eventId, limit, cursor);
3737
},
3838

3939
/**
@@ -98,9 +98,9 @@ module.exports = {
9898
* @param {String} eventId - event id
9999
* @returns {Promise<Release>}
100100
*/
101-
async release({ projectId, groupHash }) {
101+
async release({ projectId, id: eventId }) {
102102
const factory = new EventsFactory(new ObjectID(projectId));
103-
const release = await factory.getEventRelease(groupHash);
103+
const release = await factory.getEventRelease(eventId);
104104

105105
return release;
106106
},
@@ -115,10 +115,10 @@ module.exports = {
115115
* @param {UserInContext} user - user context
116116
* @return {Promise<boolean>}
117117
*/
118-
async visitEvent(_obj, { project, groupHash }, { user }) {
118+
async visitEvent(_obj, { project, id }, { user }) {
119119
const factory = new EventsFactory(project);
120120

121-
const { result } = await factory.visitEvent(groupHash, user.id);
121+
const { result } = await factory.visitEvent(id, user.id);
122122

123123
return !!result.ok;
124124
},
@@ -132,10 +132,10 @@ module.exports = {
132132
* @param {string} mark - mark to set
133133
* @return {Promise<boolean>}
134134
*/
135-
async toggleEventMark(_obj, { project, groupHash, mark }) {
135+
async toggleEventMark(_obj, { project, eventId, mark }) {
136136
const factory = new EventsFactory(project);
137137

138-
const { result } = await factory.toggleEventMark(groupHash, mark);
138+
const { result } = await factory.toggleEventMark(eventId, mark);
139139

140140
return !!result.ok;
141141
},
@@ -157,7 +157,7 @@ module.exports = {
157157
* @return {Promise<boolean>}
158158
*/
159159
async updateAssignee(_obj, { input }, { factories, user }) {
160-
const { projectId, groupHash, assignee } = input;
160+
const { projectId, eventId, assignee } = input;
161161
const factory = new EventsFactory(projectId);
162162

163163
const userExists = await factories.usersFactory.findById(assignee);
@@ -179,7 +179,7 @@ module.exports = {
179179
};
180180
}
181181

182-
const { result } = await factory.updateAssignee(groupHash, assignee);
182+
const { result } = await factory.updateAssignee(eventId, assignee);
183183

184184
const assigneeData = await factories.usersFactory.dataLoaders.userById.load(assignee);
185185

@@ -189,7 +189,7 @@ module.exports = {
189189
assigneeId: assignee,
190190
projectId,
191191
whoAssignedId: user.id,
192-
groupHash,
192+
eventId,
193193
},
194194
});
195195

@@ -208,10 +208,10 @@ module.exports = {
208208
* @return {Promise<boolean>}
209209
*/
210210
async removeAssignee(_obj, { input }) {
211-
const { projectId, groupHash } = input;
211+
const { projectId, eventId } = input;
212212
const factory = new EventsFactory(projectId);
213213

214-
const { result } = await factory.updateAssignee(groupHash, '');
214+
const { result } = await factory.updateAssignee(eventId, '');
215215

216216
return {
217217
success: !!result.ok,

src/typeDefs/event.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ type Event {
242242
"""
243243
Event repetitions
244244
"""
245-
repetitions(cursor: ID = undefined, limit: Int = 10): [Event!]
245+
repetitions(cursor: ID = null, limit: Int = 10): [Event!]
246246
247247
"""
248248
Array of users who visited event
@@ -339,9 +339,9 @@ input UpdateAssigneeInput {
339339
projectId: ID!
340340
341341
"""
342-
Event group hash
342+
Event id
343343
"""
344-
groupHash: ID!
344+
eventId: ID!
345345
346346
"""
347347
Assignee id to set
@@ -370,7 +370,7 @@ input RemoveAssigneeInput {
370370
"""
371371
ID of the selected event
372372
"""
373-
groupHash: ID!
373+
eventId: ID!
374374
}
375375
376376
type RemoveAssigneeResponse {
@@ -415,9 +415,9 @@ extend type Mutation {
415415
project: ID!
416416
417417
"""
418-
Event group hash
418+
EvenID of the event to set the mark
419419
"""
420-
groupHash: ID!
420+
eventId: ID!
421421
422422
"""
423423
Mark to set

0 commit comments

Comments
 (0)