From 33bbd619c2d591f2e847c9e26c189f4bf840ba22 Mon Sep 17 00:00:00 2001 From: HF Date: Sat, 2 May 2020 21:33:18 +0200 Subject: [PATCH] allow Moon in ranking and fix lint errors in ranking.js --- src/core/ranking.js | 46 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/src/core/ranking.js b/src/core/ranking.js index 5de420e..8308f49 100644 --- a/src/core/ranking.js +++ b/src/core/ranking.js @@ -25,20 +25,54 @@ class Ranks { async updateRanking() { // recalculate ranking column - await Model.query('SET @r=0; UPDATE Users SET ranking= @r:= (@r + 1) WHERE NOT id= 18 ORDER BY totalPixels DESC;'); - await Model.query('SET @r=0; UPDATE Users SET dailyRanking= @r:= (@r + 1) WHERE NOT id= 18 ORDER BY dailyTotalPixels DESC;'); + await Model.query( + // eslint-disable-next-line max-len + 'SET @r=0; UPDATE Users SET ranking= @r:= (@r + 1) ORDER BY totalPixels DESC;', + ); + await Model.query( + // eslint-disable-next-line max-len + 'SET @r=0; UPDATE Users SET dailyRanking= @r:= (@r + 1) ORDER BY dailyTotalPixels DESC;', + ); // populate dictionaries const ranking = await RegUser.findAll({ - attributes: ['name', 'totalPixels', 'ranking', 'dailyRanking', 'dailyTotalPixels', [Sequelize.fn('DATEDIFF', Sequelize.literal('CURRENT_TIMESTAMP'), Sequelize.col('createdAt')), 'age']], + attributes: [ + 'name', + 'totalPixels', + 'ranking', + 'dailyRanking', + 'dailyTotalPixels', + [ + Sequelize.fn( + 'DATEDIFF', + Sequelize.literal('CURRENT_TIMESTAMP'), + Sequelize.col('createdAt'), + ), + 'age', + ], + ], limit: 100, - where: { id: { [Sequelize.Op.notIn]: [18, 51] } }, + where: { id: { [Sequelize.Op.notIn]: [51, 1] } }, order: ['ranking'], raw: true, }); const dailyRanking = await RegUser.findAll({ - attributes: ['name', 'totalPixels', 'ranking', 'dailyRanking', 'dailyTotalPixels', [Sequelize.fn('DATEDIFF', Sequelize.literal('CURRENT_TIMESTAMP'), Sequelize.col('createdAt')), 'age']], + attributes: [ + 'name', + 'totalPixels', + 'ranking', + 'dailyRanking', + 'dailyTotalPixels', + [ + Sequelize.fn( + 'DATEDIFF', + Sequelize.literal('CURRENT_TIMESTAMP'), + Sequelize.col('createdAt'), + ), + 'age', + ], + ], limit: 100, - where: { id: { [Sequelize.Op.notIn]: [18, 51] } }, + where: { id: { [Sequelize.Op.notIn]: [51, 1] } }, order: ['dailyRanking'], raw: true, });