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,
ref: 'Casters',
}],
stats: [{
type: Schema.Types.ObjectId,
ref: 'Stats'
}],
})
const Stream = model('Streams', streams)

@ -2,6 +2,7 @@ const channels = [
'rosters',
'matches',
'streams',
'stats',
'events',
'casters',
'hosts',

@ -1,6 +1,7 @@
const events = require('../models/events')
const rosters = require('../models/rosters')
const matches = require('../models/matches')
const stats = require('../models/stats')
const streams = require('../models/streams')
const casters = require('../models/casters')
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 = {
getAll: async () => {
return await streams.find().exec()
@ -83,13 +107,13 @@ const streamFns = {
return await streams.find().populate('event').populate({
path: 'matches',
populate: [{ path: 'orange' }, { path: 'blue' }],
}).populate('casters').populate('hosts').lean().exec()
}).populate('casters').populate('hosts').populate('stats').lean().exec()
},
getById: async (id) => {
return await streams.findById(id).populate('event').populate({
path: 'matches',
populate: [{ path: 'orange' }, { path: 'blue' }],
}).populate('casters').populate('hosts').lean().exec()
}).populate('casters').populate('hosts').populate('stats').lean().exec()
},
update: async(id, data) => {
return await streams.findByIdAndUpdate(id, data).exec()
@ -189,6 +213,7 @@ module.exports = {
'events': eventFns,
'rosters': rosterFns,
'matches': matchFns,
'stats': statsFns,
'streams': streamFns,
'casters': casterFns,
'hosts': hostFns,

Loading…
Cancel
Save