59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
import { Router } from 'express'
|
|
import { sqlite } from '../libs/database/init.js'
|
|
import wrapper from '../libs/database/wrapper.js'
|
|
|
|
const finishApi = Router()
|
|
|
|
/* TODO: precalculate this */
|
|
finishApi.get(
|
|
'/count',
|
|
(req, res) => {
|
|
const finishes = sqlite.prepare(`SELECT COUNT(*) as count FROM race`).get()
|
|
|
|
return res.json({
|
|
success: true,
|
|
response: finishes.count,
|
|
})
|
|
}
|
|
)
|
|
|
|
finishApi.get(
|
|
'/finishedMaps/:player',
|
|
(req, res) => {
|
|
/* Check if player exists */
|
|
if(!wrapper.playerExists(req.params.player)) {
|
|
return res.json({
|
|
success: false,
|
|
response: "No such player!"
|
|
})
|
|
}
|
|
const finishes = wrapper.finishedMaps(req.params.player)
|
|
|
|
return res.json({
|
|
success: true,
|
|
response: finishes,
|
|
})
|
|
}
|
|
)
|
|
|
|
finishApi.get(
|
|
'/unfinishedMaps/:player',
|
|
(req, res) => {
|
|
/* Check if player exists */
|
|
if(!wrapper.playerExists(req.params.player)) {
|
|
return res.json({
|
|
success: false,
|
|
response: "No such player!"
|
|
})
|
|
}
|
|
const finishes = wrapper.unfinishedMaps(req.params.player)
|
|
|
|
return res.json({
|
|
success: true,
|
|
response: finishes,
|
|
})
|
|
}
|
|
)
|
|
|
|
|
|
export default finishApi |