wrap up game stats api
This commit is contained in:
@@ -14,9 +14,15 @@ app.get('/', (req, res) => {
|
|||||||
res.send('Hello World!')
|
res.send('Hello World!')
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post('/api/serverstats/gamestats', async (req, res) => {
|
app.post('/api/serverstats/gamestats', jsonParser, async (req, res) => {
|
||||||
const serverGameStats =
|
|
||||||
await database.query(
|
const month = req.body.monthId % 12
|
||||||
|
const year = Math.floor(req.body.monthId / 12) + 2023
|
||||||
|
|
||||||
|
const startDate = new Date(year, month, 1)
|
||||||
|
const endDate = new Date(year, month + 1, -1)
|
||||||
|
|
||||||
|
const serverGameStats = await database.query(
|
||||||
'SELECT ' +
|
'SELECT ' +
|
||||||
'COUNT(*) as TotalGames, ' +
|
'COUNT(*) as TotalGames, ' +
|
||||||
'SUM(CASE WHEN status = "Complete" THEN 1 ELSE 0 END) as Complete, ' +
|
'SUM(CASE WHEN status = "Complete" THEN 1 ELSE 0 END) as Complete, ' +
|
||||||
@@ -24,8 +30,14 @@ app.post('/api/serverstats/gamestats', async (req, res) => {
|
|||||||
'SUM(CASE WHEN status = "Pending" THEN 1 ELSE 0 END) as Pending, ' +
|
'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(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 ' +
|
'SUM(payoutIP) / SUM(CASE WHEN status = "Complete" THEN 1 ELSE 0 END) as AverageIP ' +
|
||||||
'FROM Games WHERE postdate BETWEEN 1706788520 AND 1709207720',
|
'FROM Games WHERE postdate BETWEEN :startSeconds AND :endSeconds',
|
||||||
{ type: QueryTypes.SELECT }
|
{
|
||||||
|
type: QueryTypes.SELECT,
|
||||||
|
replacements: {
|
||||||
|
startSeconds: startDate.getTime() / 1000,
|
||||||
|
endSeconds: endDate.getTime() / 1000
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
res.json(serverGameStats[0])
|
res.json(serverGameStats[0])
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user