Return undefined if fetch failed
This commit is contained in:
parent
193c46caa5
commit
220734819b
|
@ -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})
|
||||
|
|
|
@ -119,19 +119,19 @@
|
|||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="leaderboard">
|
||||
<h2> Team records! </h2>
|
||||
{% for record in teamLeaderboard %}
|
||||
<div class="rank">
|
||||
<img class="country-image" data-src="https://ddnet.tw/countryflags/{{ record.server }}.png">
|
||||
<p class="rank-position">{{ record.teamrank }}.</p>
|
||||
<p class="rank-player">{{ record.players.join(", ") }}</p>
|
||||
<p class="rank-time">{{ utils.fancyTime(record.time) }}</p>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% if map.finishes.team %}
|
||||
<div class="leaderboard">
|
||||
<h2> Team records! </h2>
|
||||
{% for record in teamLeaderboard %}
|
||||
<div class="rank">
|
||||
<img class="country-image" data-src="https://ddnet.tw/countryflags/{{ record.server }}.png">
|
||||
<p class="rank-position">{{ record.teamrank }}.</p>
|
||||
<p class="rank-player">{{ record.players.join(", ") }}</p>
|
||||
<p class="rank-time">{{ utils.fancyTime(record.time) }}</p>
|
||||
</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
|
||||
}]
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user