Commit 5f8fbf53 authored by Matthieu - Greep's avatar Matthieu - Greep

Create getPlayerVote.js

parent 1c4cbe5d
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) {
const mapId = req.query.map,
player = req.query.player;
if (!mapId) {
return errorHandler(res, 400, 'Missing map id');
}
if (!player) {
return errorHandler(res, 400, 'Missing player login');
}
sql.query('SELECT * FROM votes WHERE map = ? AND player = ?', [mapId, player], (err, sqlRes)=>{
if (err) {
console.log(err);
errorHandler(res, 500, 'Internal server error');
} else {
if (sqlRes.length === 0) {
return errorHandler(res, 404, 'No vote found');
}
if (sqlRes[0].map == null) {
return errorHandler(res, 404, 'Map not found');
}
if (sqlRes[0].player == null) {
return errorHandler(res, 404, 'Player not found');
}
res.json({
mapUid: sqlRes[0].map,
playerLogin: sqlRes[0].player,
vote: sqlRes[0].vote,
date: sqlRes[0].date
});
}
});
});
};
\ 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