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

Create mostVotedMaps.js

parent f08d3d64
Pipeline #449 passed with stage
in 50 seconds
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 map, COUNT(*) AS votes FROM votes GROUP BY map ORDER BY votes DESC', (err, sqlRes)=>{
if (err) {
console.log(err);
errorHandler(res, 500, 'Internal server error');
} else {
let maps = {};
for (let i = 0; i < sqlRes.length; i++) {
maps[sqlRes[i].map] = sqlRes[i].votes;
}
res.json(maps);
}
});
});
};
\ 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