Ajout panel + récup infos depuis SQL + fix noms de fichiers

This commit is contained in:
Zachary Guénot
2023-05-10 01:53:55 +02:00
parent 172f811e91
commit de01c981f8
14 changed files with 162 additions and 58 deletions

23
utils/getRewardData.js Normal file
View File

@@ -0,0 +1,23 @@
const mysql = require('mysql2/promise')
module.exports = async function () {
// Create a connection to the MySQL database
const connection = await mysql.createConnection({
host: process.env.MYSQL_HOST,
port: process.env.MYSQL_PORT,
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASSWORD,
database: process.env.MYSQL_DATABASE
})
// Retrieve the count of rewards claimed by each user, sorted by count
let results = await connection.execute('SELECT * FROM rewards ORDER BY count DESC')
.then(async ([rows, fields]) => { return rows })
.catch(error => { console.error(error) })
// Terminate the connection to the database
await connection.end()
if (!results) return { error: 'No scoreboard data found' }
return results
}