diff --git a/libs/database/wrapper.js b/libs/database/wrapper.js index 002edba..8593407 100644 --- a/libs/database/wrapper.js +++ b/libs/database/wrapper.js @@ -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}) diff --git a/views/pages/mapSingle.njk b/views/pages/mapSingle.njk index 877f5c5..4129b7d 100644 --- a/views/pages/mapSingle.njk +++ b/views/pages/mapSingle.njk @@ -119,19 +119,19 @@ {% endfor %} - -
-

Team records!

- {% for record in teamLeaderboard %} -
- -

{{ record.teamrank }}.

-

{{ record.players.join(", ") }}

-

{{ utils.fancyTime(record.time) }}

-
- {% endfor %} -
- + {% if map.finishes.team %} +
+

Team records!

+ {% for record in teamLeaderboard %} +
+ +

{{ record.teamrank }}.

+

{{ record.players.join(", ") }}

+

{{ utils.fancyTime(record.time) }}

+
+ {% endfor %} +
+ {% endif %}

Record over time

@@ -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 }] } })