From 20831364ef5f2dbd82e5b764135892cb63ab0259 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 10 Feb 2019 21:58:43 +0100 Subject: [PATCH] Adding possibility to query for self --- src/schema/queries/Events.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/schema/queries/Events.js b/src/schema/queries/Events.js index c50241e10..3e7a3d44f 100644 --- a/src/schema/queries/Events.js +++ b/src/schema/queries/Events.js @@ -30,7 +30,7 @@ const resolve = (parent, { minEndDate, maxEndDate, }, { userId }) => { - if (state === UNPUBLISHED && hostId !== userId) { + if (state === UNPUBLISHED && hostId !== userId && hostId !== 'self') { throw new AuthentificationError('You cannot get unpublished events of other users.'); } @@ -39,7 +39,8 @@ const resolve = (parent, { Event.find( Object.assign( state ? { state } : { state: { $nin: [UNPUBLISHED, ARCHIVED] } }, - hostId ? { hostId } : {}, + (hostId && hostId !== 'self') ? { hostId } : {}, + (hostId === 'self') ? { hostId: userId } : {}, participantId ? { participants: { $elemMatch: { participantId } } } : {}, inviteeId ? { invitations: { $elemMatch: { inviteeId } } } : {}, minStartDate || maxStartDate