diff --git a/backend/src/app.ts b/backend/src/app.ts index 6450863..d8e029d 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -1,6 +1,6 @@ import express from 'express' import { json } from 'body-parser' -import { Sequelize, Op } from 'sequelize' +import { Sequelize, Op, QueryTypes } from 'sequelize' import { database, Character, Game, Pick, App } from './db' import { OrderByParser, FilterParser } from './tokenizer' @@ -14,6 +14,22 @@ app.get('/', (req, res) => { res.send('Hello World!') }) +app.post('/api/serverstats/gamestats', async (req, res) => { + const serverGameStats = + await database.query( + 'SELECT ' + + 'COUNT(*) as TotalGames, ' + + 'SUM(CASE WHEN status = "Complete" THEN 1 ELSE 0 END) as Complete, ' + + 'SUM(CASE WHEN status = "Postponed" THEN 1 ELSE 0 END) as Postponed, ' + + 'SUM(CASE WHEN status = "Pending" THEN 1 ELSE 0 END) as Pending, ' + + 'SUM(payoutEB) / SUM(CASE WHEN status = "Complete" THEN 1 ELSE 0 END) as AverageEB, ' + + 'SUM(payoutIP) / SUM(CASE WHEN status = "Complete" THEN 1 ELSE 0 END) as AverageIP ' + + 'FROM Games WHERE postdate BETWEEN 1706788520 AND 1709207720', + { type: QueryTypes.SELECT } + ) + res.json(serverGameStats[0]) +}) + app.get('/api/character/:characterId', async (req, res) => { res.send(await Character.findOne({ where: { id: req.params['characterId'] } })) })