feat: add stats support in slap

main
Ayush Mukherjee 1 year ago
parent aca336e8ef
commit fcb0651579

@ -0,0 +1,47 @@
const { Schema, model } = require('mongoose')
const stats = new Schema({
name: {
type: String,
required: true,
},
name_arabic: {
type: String,
},
name_jpn: {
type: String,
},
image: {
type: String,
required: true,
},
image_full: {
type: Boolean,
default: false,
required: true,
},
win: {
type: String,
required: true,
},
goals: {
type: String,
required: true,
},
shots: {
type: String,
required: true,
},
saves: {
type: String,
required: true,
},
assists: {
type: String,
required: true,
},
})
const Stat = model('Stats', stats)
module.exports = Stat

@ -27,6 +27,10 @@ const streams = new Schema({
type: Schema.Types.ObjectId, type: Schema.Types.ObjectId,
ref: 'Casters', ref: 'Casters',
}], }],
stats: [{
type: Schema.Types.ObjectId,
ref: 'Stats'
}],
}) })
const Stream = model('Streams', streams) const Stream = model('Streams', streams)

@ -2,6 +2,7 @@ const channels = [
'rosters', 'rosters',
'matches', 'matches',
'streams', 'streams',
'stats',
'events', 'events',
'casters', 'casters',
'hosts', 'hosts',
@ -29,4 +30,4 @@ module.exports = {
channelEvents, channelEvents,
channels, channels,
events, events,
}; };

@ -1,6 +1,7 @@
const events = require('../models/events') const events = require('../models/events')
const rosters = require('../models/rosters') const rosters = require('../models/rosters')
const matches = require('../models/matches') const matches = require('../models/matches')
const stats = require('../models/stats')
const streams = require('../models/streams') const streams = require('../models/streams')
const casters = require('../models/casters') const casters = require('../models/casters')
const hosts = require('../models/hosts') const hosts = require('../models/hosts')
@ -75,6 +76,29 @@ const matchFns = {
} }
} }
const statsFns = {
getAll: async () => {
return await stats.find().exec()
},
getById: async (id) => {
return await stats.findById(id).exec()
},
update: async(id, data) => {
return await stats.findByIdAndUpdate(id, data).exec()
},
delete: async (id) => {
return await stats.findByIdAndDelete(id).exec()
},
create: async (data) => {
try {
const ev = new stats(data)
await ev.save();
} catch (e) {
console.warn(e)
}
}
}
const streamFns = { const streamFns = {
getAll: async () => { getAll: async () => {
return await streams.find().exec() return await streams.find().exec()
@ -83,13 +107,13 @@ const streamFns = {
return await streams.find().populate('event').populate({ return await streams.find().populate('event').populate({
path: 'matches', path: 'matches',
populate: [{ path: 'orange' }, { path: 'blue' }], populate: [{ path: 'orange' }, { path: 'blue' }],
}).populate('casters').populate('hosts').lean().exec() }).populate('casters').populate('hosts').populate('stats').lean().exec()
}, },
getById: async (id) => { getById: async (id) => {
return await streams.findById(id).populate('event').populate({ return await streams.findById(id).populate('event').populate({
path: 'matches', path: 'matches',
populate: [{ path: 'orange' }, { path: 'blue' }], populate: [{ path: 'orange' }, { path: 'blue' }],
}).populate('casters').populate('hosts').lean().exec() }).populate('casters').populate('hosts').populate('stats').lean().exec()
}, },
update: async(id, data) => { update: async(id, data) => {
return await streams.findByIdAndUpdate(id, data).exec() return await streams.findByIdAndUpdate(id, data).exec()
@ -189,6 +213,7 @@ module.exports = {
'events': eventFns, 'events': eventFns,
'rosters': rosterFns, 'rosters': rosterFns,
'matches': matchFns, 'matches': matchFns,
'stats': statsFns,
'streams': streamFns, 'streams': streamFns,
'casters': casterFns, 'casters': casterFns,
'hosts': hostFns, 'hosts': hostFns,

Loading…
Cancel
Save