add option to get populated data for streams

main
Ayush Mukherjee 4 years ago
parent 1bf671fdfe
commit c4c1c86249

@ -14,7 +14,9 @@ const events = [
'delete', 'delete',
]; ];
const channelEvents = []; const channelEvents = [
'streams:full',
];
channels.forEach((c) => { channels.forEach((c) => {
events.forEach((e) => { events.forEach((e) => {

@ -86,10 +86,12 @@ const matchFns = {
const streamFns = { const streamFns = {
getAll: async () => { getAll: async () => {
return await streams.find().exec() return await streams.find().exec()
// return await streams.find().populate('event').populate({ },
// path: 'matches', getAllPop: async () => {
// populate: [{ path: 'orange' }, { path: 'blue' }], return await streams.find().populate('event').populate({
// }).populate('casters').populate('hosts').exec() path: 'matches',
populate: [{ path: 'orange' }, { path: 'blue' }],
}).populate('casters').populate('hosts').exec()
}, },
getById: async (id) => { getById: async (id) => {
return await streams.findById(id).populate('event').populate('matches').populate('casters').populate('hosts').exec() return await streams.findById(id).populate('event').populate('matches').populate('casters').populate('hosts').exec()

@ -33,6 +33,9 @@ const handleMsg = async (msg, id) => {
event: `${channel}:read`, event: `${channel}:read`,
data: await crud[channel].getAll(), 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)) connections[id].connection.send(JSON.stringify(dm))
} else if (d.hasOwnProperty('event') && channelEvents.indexOf(d.event) !== -1) { } else if (d.hasOwnProperty('event') && channelEvents.indexOf(d.event) !== -1) {
const ev = d.event.split(':') const ev = d.event.split(':')

Loading…
Cancel
Save