Return undefined if fetch failed
This commit is contained in:
parent
193c46caa5
commit
220734819b
|
@ -59,6 +59,9 @@ export function player(player) {
|
||||||
/* Misc */
|
/* Misc */
|
||||||
const firstFinish = sqlite.prepare(`SELECT map, time, date, server FROM race WHERE player = ? ORDER BY date ASC LIMIT 1`).get(player)
|
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 */
|
/* Points */
|
||||||
let points = {}
|
let points = {}
|
||||||
let rank = {}
|
let rank = {}
|
||||||
|
@ -100,6 +103,9 @@ export function mapCategory(category) {
|
||||||
const maps = sqlite.prepare(`
|
const maps = sqlite.prepare(`
|
||||||
SELECT * FROM maps WHERE category = ?`).all(category)
|
SELECT * FROM maps WHERE category = ?`).all(category)
|
||||||
|
|
||||||
|
if(!maps)
|
||||||
|
return undefined
|
||||||
|
|
||||||
for(const map of maps) {
|
for(const map of maps) {
|
||||||
output.push(prettyifyMap(map))
|
output.push(prettyifyMap(map))
|
||||||
}
|
}
|
||||||
|
@ -130,9 +136,10 @@ export function allMaps() {
|
||||||
* @returns {object} An object containing map data
|
* @returns {object} An object containing map data
|
||||||
*/
|
*/
|
||||||
export function prettyifyMap(a) {
|
export function prettyifyMap(a) {
|
||||||
let output
|
if(!a)
|
||||||
|
return undefined
|
||||||
|
|
||||||
output = {
|
let output = {
|
||||||
map: a.map,
|
map: a.map,
|
||||||
category: a.category,
|
category: a.category,
|
||||||
points: a.points,
|
points: a.points,
|
||||||
|
@ -167,8 +174,8 @@ export function allMaps() {
|
||||||
*/
|
*/
|
||||||
export function leaderboardRace(map, start, end) {
|
export function leaderboardRace(map, start, end) {
|
||||||
const leaderboard = sqlite.prepare(`
|
const leaderboard = sqlite.prepare(`
|
||||||
SELECT rank, time, date, player, server FROM rankings WHERE map = ? AND rank >= ? AND rank <= ?`)
|
SELECT rank, time, date, player, server FROM rankings WHERE map = ? LIMIT ?, ?`)
|
||||||
.all(map, start, end)
|
.all(map, start -1, end)
|
||||||
|
|
||||||
return leaderboard
|
return leaderboard
|
||||||
}
|
}
|
||||||
|
@ -193,6 +200,9 @@ export function leaderboardRace(map, start, end) {
|
||||||
let players = []
|
let players = []
|
||||||
const b = sqlite.prepare(`SELECT player FROM teamrankings WHERE map = ? AND teamrank = ?`)
|
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)) {
|
for(const player of b.iterate(map, teamrank.teamrank)) {
|
||||||
players.push(player.player)
|
players.push(player.player)
|
||||||
}
|
}
|
||||||
|
@ -251,6 +261,9 @@ export function finishedMaps(player) {
|
||||||
WHERE a.player = ?
|
WHERE a.player = ?
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
if(!finishesStmt)
|
||||||
|
return undefined
|
||||||
|
|
||||||
let finishes = {
|
let finishes = {
|
||||||
Novice: [],
|
Novice: [],
|
||||||
Moderate: [],
|
Moderate: [],
|
||||||
|
@ -300,6 +313,9 @@ export function finishedMaps(player) {
|
||||||
ORDER BY b.category ASC;
|
ORDER BY b.category ASC;
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
if(!maps)
|
||||||
|
return undefined
|
||||||
|
|
||||||
let unfinished = {
|
let unfinished = {
|
||||||
Novice: [],
|
Novice: [],
|
||||||
Moderate: [],
|
Moderate: [],
|
||||||
|
@ -322,6 +338,9 @@ export function finishedMaps(player) {
|
||||||
export function graphMap(map) {
|
export function graphMap(map) {
|
||||||
const finishes = sqlite.prepare(`SELECT * FROM graphRecordCache WHERE map = ? ORDER BY date`)
|
const finishes = sqlite.prepare(`SELECT * FROM graphRecordCache WHERE map = ? ORDER BY date`)
|
||||||
|
|
||||||
|
if(!finishes)
|
||||||
|
return undefined
|
||||||
|
|
||||||
let array = []
|
let array = []
|
||||||
for (const record of finishes.iterate(map))
|
for (const record of finishes.iterate(map))
|
||||||
array.push({ t: record.date, y: record.time, player: record.player})
|
array.push({ t: record.date, y: record.time, player: record.player})
|
||||||
|
|
|
@ -119,19 +119,19 @@
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
{% if map.finishes.team %}
|
||||||
<div class="leaderboard">
|
<div class="leaderboard">
|
||||||
<h2> Team records! </h2>
|
<h2> Team records! </h2>
|
||||||
{% for record in teamLeaderboard %}
|
{% for record in teamLeaderboard %}
|
||||||
<div class="rank">
|
<div class="rank">
|
||||||
<img class="country-image" data-src="https://ddnet.tw/countryflags/{{ record.server }}.png">
|
<img class="country-image" data-src="https://ddnet.tw/countryflags/{{ record.server }}.png">
|
||||||
<p class="rank-position">{{ record.teamrank }}.</p>
|
<p class="rank-position">{{ record.teamrank }}.</p>
|
||||||
<p class="rank-player">{{ record.players.join(", ") }}</p>
|
<p class="rank-player">{{ record.players.join(", ") }}</p>
|
||||||
<p class="rank-time">{{ utils.fancyTime(record.time) }}</p>
|
<p class="rank-time">{{ utils.fancyTime(record.time) }}</p>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
<div class="leaderboard-history">
|
<div class="leaderboard-history">
|
||||||
<h1> Record over time </h1>
|
<h1> Record over time </h1>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
@ -152,12 +152,6 @@
|
||||||
mode: 'index',
|
mode: 'index',
|
||||||
intersect: false
|
intersect: false
|
||||||
},
|
},
|
||||||
/* This currently doesn't work :( */
|
|
||||||
callbacks: {
|
|
||||||
label: function(tooltipItem, data) {
|
|
||||||
return data[tooltipItem['index']]['player']
|
|
||||||
}
|
|
||||||
},
|
|
||||||
scales: {
|
scales: {
|
||||||
xAxes: [{
|
xAxes: [{
|
||||||
type: 'time',
|
type: 'time',
|
||||||
|
@ -168,7 +162,7 @@
|
||||||
},
|
},
|
||||||
elements: {
|
elements: {
|
||||||
point: {
|
point: {
|
||||||
radius: 6
|
radius: 0
|
||||||
},
|
},
|
||||||
line: {
|
line: {
|
||||||
fill: false
|
fill: false
|
||||||
|
@ -188,7 +182,8 @@
|
||||||
borderColor: [
|
borderColor: [
|
||||||
'#FBA7C6'
|
'#FBA7C6'
|
||||||
],
|
],
|
||||||
borderWidth: 3
|
borderWidth: 3,
|
||||||
|
lineTension: 0
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user