Commit a2830fa1 authored by Matthieu - Greep's avatar Matthieu - Greep

Create mostPlayerVoted

parent 7cb2ab0e
Pipeline #453 passed with stage
in 48 seconds
......@@ -63,6 +63,22 @@ Example response:
}
```
**GET /mostPlayerVoted**<br>
Returns the top of the players who have voted the most maps. in decreasing order (from the most player who voted to the least)<br>
There's no parameters for this request!
Example response:
```json
{
"Jtmn3kBnSSadky_mLNhp_A": 10,
"W01C9MLeQH2zZ8v_P-gXvA": 8,
"TIA7WqNETVyjWNj3RV1shQ": 5,
"c5jutptORLinoaIUmVWscA": 2,
"xTn1Lty3Tki8v7w3FBqVIA": 1
}
```
**POST /setVote**<br>
Writes the vote of a player to the respective map into the database table.<br />
⚠ You need an Authorization header with a valid token in order to do requests for this. After getting your token, set your Authorization value to `Basic yourtokenhere`
......
const path = require('path'),
scriptName = path.basename(__filename).replace(/\.js$/i,'');
/**
* @param {import('express').Express} app
* @param {import('mysql').Connection} sql
*/
module.exports = function(app, sql, token, errorHandler) {
app.get('/'+scriptName, function(req, res) {
sql.query('SELECT player, COUNT(*) AS votes FROM votes GROUP BY player ORDER BY votes DESC', (err, sqlRes)=>{
if (err) {
console.log(err);
errorHandler(res, 500, 'Internal server error');
} else {
let votes = {};
for (let i = 0; i < sqlRes.length; i++) {
votes[sqlRes[i].player] = sqlRes[i].votes;
}
res.json(votes);
}
});
});
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment