-
Notifications
You must be signed in to change notification settings - Fork 0
/
hall.js
92 lines (79 loc) · 2.11 KB
/
hall.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
class Hall {
constructor(db) {
this.db = db;
}
async getTopPlayersHtml() {
const topPlayers = await this.getTopPlayers();
let html = `
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Top 10 Players Hall</title>
<style>
body {
font-family: 'Arial', sans-serif;
margin: 20px;
}
h1 {
color: #3498db;
}
table {
border-collapse: collapse;
width: 100%;
margin-top: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 12px;
text-align: left;
}
th {
background-color: #3498db;
color: #fff;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h1>Top 10 Players Hall</h1>
<table>
<tr>
<th>Player</th>
<th>Kills</th>
<th>Deaths</th>
<th>Month/Year</th>
</tr>`;
topPlayers.forEach(player => {
html += `
<tr>
<td>${player.player_name}</td>
<td>${player.kills}</td>
<td>${player.deaths}</td>
<td>${player.month_year}</td>
</tr>`;
});
html += `
</table>
</body>
</html>`;
return html;
}
async getTopPlayers() {
try {
const topPlayers = await this.db.any(`
SELECT player_name, kills, deaths, month_year
FROM ranking
ORDER BY kills DESC
LIMIT 10
`);
return topPlayers;
} catch (error) {
console.error('Error fetching top players:', error.message || error);
return [];
}
}
}
module.exports = Hall;