Commit 354ed5c0 authored by Matthieu - Greep's avatar Matthieu - Greep

Remove error if no votes

parent 11beaeeb
Pipeline #451 passed with stage
in 1 minute and 13 seconds
...@@ -21,13 +21,28 @@ module.exports = function(app, sql, token, errorHandler) { ...@@ -21,13 +21,28 @@ module.exports = function(app, sql, token, errorHandler) {
errorHandler(res, 500, 'Internal server error'); errorHandler(res, 500, 'Internal server error');
} else { } else {
if (sqlRes.length === 0) { if (sqlRes.length === 0) {
return errorHandler(res, 404, 'No vote found'); return res.json({
mapUid: mapId,
playerLogin: player,
vote: -1,
date: ""
});
} }
if (sqlRes[0].map == null) { if (sqlRes[0].map == null) {
return errorHandler(res, 404, 'Map not found'); return res.json({
mapUid: mapId,
playerLogin: player,
vote: -1,
date: ""
});
} }
if (sqlRes[0].player == null) { if (sqlRes[0].player == null) {
return errorHandler(res, 404, 'Player not found'); return res.json({
mapUid: mapId,
playerLogin: player,
vote: -1,
date: ""
});
} }
res.json({ res.json({
......
...@@ -17,7 +17,12 @@ module.exports = function(app, sql, token, errorHandler) { ...@@ -17,7 +17,12 @@ module.exports = function(app, sql, token, errorHandler) {
errorHandler(res, 500, 'Internal server error'); errorHandler(res, 500, 'Internal server error');
} else { } else {
if (sqlRes[0].map == null) { if (sqlRes[0].map == null) {
return errorHandler(res, 404, 'Map not found'); return res.json({
mapUid: mapId,
votes: 0,
average: 0,
lastVoteDate: ""
});
} }
// Get the latest date from an array // Get the latest date from an array
const latestDate = new Date(Math.max.apply(null, sqlRes.map(function(e) { const latestDate = new Date(Math.max.apply(null, sqlRes.map(function(e) {
......
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