const events = require('../models/events') const rosters = require('../models/rosters') const matches = require('../models/matches') const streams = require('../models/streams') const casters = require('../models/casters') const hosts = require('../models/hosts') const eventFns = { getAll: async () => { return await events.find().populate('streams').exec() }, getById: async (id) => { return await events.findById(id).populate('streams').exec() }, update: async(id, data) => { return await events.findByIdAndUpdate(id, data).exec() }, delete: async (id) => { return await events.findByIdAndDelete(id).exec() }, create: async (data) => { try { const ev = new events(data) ev.save((err) => { if (err) console.warn(err) }) } catch (e) { console.warn(e) } } } const rosterFns = { getAll: async () => { return await rosters.find().exec() }, getById: async (id) => { return await rosters.findById(id).exec() }, update: async(id, data) => { return await rosters.findByIdAndUpdate(id, data).exec() }, delete: async (id) => { return await rosters.findByIdAndDelete(id).exec() }, create: async (data) => { try { const ev = new rosters(data) ev.save((err) => { if (err) console.warn(err) }) } catch (e) { console.warn(e) } } } const matchFns = { getAll: async () => { return await matches.find().populate('orange').populate('blue').exec() }, getById: async (id) => { return await matches.findById(id).populate('orange').populate('blue').exec() }, update: async(id, data) => { return await matches.findByIdAndUpdate(id, data).exec() }, delete: async (id) => { return await matches.findByIdAndDelete(id).exec() }, create: async (data) => { try { const ev = new matches(data) ev.save((err) => { if (err) console.warn(err) }) } catch (e) { console.warn(e) } } } const streamFns = { getAll: async () => { return await streams.find().populate('event').populate('matches').populate('casters').populate('hosts').exec() }, getById: async (id) => { return await streams.findById(id).populate('event').populate('matches').populate('casters').populate('hosts').exec() }, update: async(id, data) => { return await streams.findByIdAndUpdate(id, data).exec() }, delete: async (id) => { return await streams.findByIdAndDelete(id).exec() }, create: async (data) => { try { const ev = new streams(data) ev.save((err) => { if (err) console.warn(err) }) } catch (e) { console.warn(e) } } } const casterFns = { getAll: async () => { return await casters.find().exec() }, getById: async (id) => { return await casters.findById(id).exec() }, update: async(id, data) => { return await casters.findByIdAndUpdate(id, data).exec() }, delete: async (id) => { return await casters.findByIdAndDelete(id).exec() }, create: async (data) => { try { const ev = new casters(data) ev.save((err) => { if (err) console.warn(err) }) } catch (e) { console.warn(e) } } } const hostFns = { getAll: async () => { return await hosts.find().exec() }, getById: async (id) => { return await hosts.findById(id).exec() }, update: async(id, data) => { return await hosts.findByIdAndUpdate(id, data).exec() }, delete: async (id) => { return await hosts.findByIdAndDelete(id).exec() }, create: async (data) => { try { const ev = new hosts(data) ev.save((err) => { if (err) console.warn(err) }) } catch (e) { console.warn(e) } } } module.exports = { 'events': eventFns, 'rosters': rosterFns, 'matches': matchFns, 'streams': streamFns, 'casters': casterFns, 'hosts': hostFns, }