Return undefined if fetch failed

This commit is contained in:
furo 2021-11-05 11:56:31 +01:00
parent 193c46caa5
commit 220734819b
2 changed files with 39 additions and 25 deletions

View File

@ -59,6 +59,9 @@ export function player(player) {
/* Misc */
const firstFinish = sqlite.prepare(`SELECT map, time, date, server FROM race WHERE player = ? ORDER BY date ASC LIMIT 1`).get(player)
if(!firstFinish)
return undefined
/* Points */
let points = {}
let rank = {}
@ -100,6 +103,9 @@ export function mapCategory(category) {
const maps = sqlite.prepare(`
SELECT * FROM maps WHERE category = ?`).all(category)
if(!maps)
return undefined
for(const map of maps) {
output.push(prettyifyMap(map))
}
@ -130,9 +136,10 @@ export function allMaps() {
* @returns {object} An object containing map data
*/
export function prettyifyMap(a) {
let output
if(!a)
return undefined
output = {
let output = {
map: a.map,
category: a.category,
points: a.points,
@ -167,8 +174,8 @@ export function allMaps() {
*/
export function leaderboardRace(map, start, end) {
const leaderboard = sqlite.prepare(`
SELECT rank, time, date, player, server FROM rankings WHERE map = ? AND rank >= ? AND rank <= ?`)
.all(map, start, end)
SELECT rank, time, date, player, server FROM rankings WHERE map = ? LIMIT ?, ?`)
.all(map, start -1, end)
return leaderboard
}
@ -193,6 +200,9 @@ export function leaderboardRace(map, start, end) {
let players = []
const b = sqlite.prepare(`SELECT player FROM teamrankings WHERE map = ? AND teamrank = ?`)
if(!b)
return undefined
for(const player of b.iterate(map, teamrank.teamrank)) {
players.push(player.player)
}
@ -251,6 +261,9 @@ export function finishedMaps(player) {
WHERE a.player = ?
`)
if(!finishesStmt)
return undefined
let finishes = {
Novice: [],
Moderate: [],
@ -300,6 +313,9 @@ export function finishedMaps(player) {
ORDER BY b.category ASC;
`)
if(!maps)
return undefined
let unfinished = {
Novice: [],
Moderate: [],
@ -322,6 +338,9 @@ export function finishedMaps(player) {
export function graphMap(map) {
const finishes = sqlite.prepare(`SELECT * FROM graphRecordCache WHERE map = ? ORDER BY date`)
if(!finishes)
return undefined
let array = []
for (const record of finishes.iterate(map))
array.push({ t: record.date, y: record.time, player: record.player})

View File

@ -119,7 +119,7 @@
</div>
{% endfor %}
</div>
{% if map.finishes.team %}
<div class="leaderboard">
<h2> Team records! </h2>
{% for record in teamLeaderboard %}
@ -131,7 +131,7 @@
</div>
{% endfor %}
</div>
{% endif %}
<div class="leaderboard-history">
<h1> Record over time </h1>
<div class="container">
@ -152,12 +152,6 @@
mode: 'index',
intersect: false
},
/* This currently doesn't work :( */
callbacks: {
label: function(tooltipItem, data) {
return data[tooltipItem['index']]['player']
}
},
scales: {
xAxes: [{
type: 'time',
@ -168,7 +162,7 @@
},
elements: {
point: {
radius: 6
radius: 0
},
line: {
fill: false
@ -188,7 +182,8 @@
borderColor: [
'#FBA7C6'
],
borderWidth: 3
borderWidth: 3,
lineTension: 0
}]
}
})