From c4c1c862498e839a35b83fe740c44660c353e130 Mon Sep 17 00:00:00 2001 From: Ayush Mukherjee Date: Fri, 19 Mar 2021 13:37:52 +0530 Subject: [PATCH] add option to get populated data for streams --- src/ws/channels.js | 4 +++- src/ws/crud.js | 10 ++++++---- src/ws/handler.js | 3 +++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/ws/channels.js b/src/ws/channels.js index 5fea53a..b4e94e3 100644 --- a/src/ws/channels.js +++ b/src/ws/channels.js @@ -14,7 +14,9 @@ const events = [ 'delete', ]; -const channelEvents = []; +const channelEvents = [ + 'streams:full', +]; channels.forEach((c) => { events.forEach((e) => { diff --git a/src/ws/crud.js b/src/ws/crud.js index 5b71685..671d057 100644 --- a/src/ws/crud.js +++ b/src/ws/crud.js @@ -86,10 +86,12 @@ const matchFns = { const streamFns = { getAll: async () => { return await streams.find().exec() - // return await streams.find().populate('event').populate({ - // path: 'matches', - // populate: [{ path: 'orange' }, { path: 'blue' }], - // }).populate('casters').populate('hosts').exec() + }, + getAllPop: async () => { + return await streams.find().populate('event').populate({ + path: 'matches', + populate: [{ path: 'orange' }, { path: 'blue' }], + }).populate('casters').populate('hosts').exec() }, getById: async (id) => { return await streams.findById(id).populate('event').populate('matches').populate('casters').populate('hosts').exec() diff --git a/src/ws/handler.js b/src/ws/handler.js index 43009bf..b11aa30 100644 --- a/src/ws/handler.js +++ b/src/ws/handler.js @@ -33,6 +33,9 @@ const handleMsg = async (msg, id) => { event: `${channel}:read`, data: await crud[channel].getAll(), } + if (channel === 'streams' && d.subscribe === 'streams:full') { + dm.data = await crud[channel].getAllPop() + } connections[id].connection.send(JSON.stringify(dm)) } else if (d.hasOwnProperty('event') && channelEvents.indexOf(d.event) !== -1) { const ev = d.event.split(':')