From 09410ff1c5dd7d6f9f7e524f951df12d0efae11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 10 Sep 2019 20:40:49 -0400 Subject: [PATCH] feat: don't hardcode numberic fields in user search --- src/user/search.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/user/search.js b/src/user/search.js index 5e6f8829c1..93ae92ddae 100644 --- a/src/user/search.js +++ b/src/user/search.js @@ -4,6 +4,7 @@ const meta = require('../meta'); const plugins = require('../plugins'); const db = require('../database'); +const utils = require('../utils'); module.exports = function (User) { User.search = async function (data) { @@ -108,7 +109,11 @@ module.exports = function (User) { } function sortUsers(userData, sortBy) { - if (sortBy === 'joindate' || sortBy === 'postcount' || sortBy === 'reputation') { + if (!userData || !userData.length) { + return; + } + const isNumeric = utils.isNumber(userData[0][sortBy]); + if (isNumeric) { userData.sort((u1, u2) => u2[sortBy] - u1[sortBy]); } else { userData.sort(function (u1, u2) {