From 7ccb4125343672000991cc8080192a289f3462f2 Mon Sep 17 00:00:00 2001 From: t123yh Date: Mon, 28 Aug 2017 23:02:59 +0800 Subject: [PATCH] Fix tag SQL error. --- modules/problem.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/problem.js b/modules/problem.js index 74312da..2c8ad01 100644 --- a/modules/problem.js +++ b/modules/problem.js @@ -130,7 +130,7 @@ app.get('/problems/search', async (req, res) => { } let paginate = syzoj.utils.paginate(await Problem.count(where), req.query.page, syzoj.config.page.problem); - let problems = await Problem.query(paginate, where, [syzoj.db.literal('`id` = ' + id + ' DESC'), [sortVal, order]]); + let problems = await Problem.query(paginate, where, [syzoj.db.literal('`id` = ' + id + ' DESC'), [sortVal, order]]); await problems.forEachAsync(async problem => { problem.allowedEdit = await problem.isAllowedEditBy(res.locals.user); @@ -162,9 +162,11 @@ app.get('/problems/tag/:tagIDs', async (req, res) => { if (!['id', 'title', 'rating', 'ac_num', 'submit_num', 'ac_rate'].includes(sort) || !['asc', 'desc'].includes(order)) { throw new ErrorMessage('错误的排序参数。'); } - let sortVal = sort; + let sortVal; if (sort === 'ac_rate') { - sortVal = 'ac_num / submit_num'; + sortVal = '`problem`.`ac_num` / `problem`.`submit_num`'; + } else { + sortVal = '`problem`.`' + sort + '`'; } // Validate the tagIDs @@ -192,7 +194,7 @@ app.get('/problems/tag/:tagIDs', async (req, res) => { } let paginate = syzoj.utils.paginate(await Problem.count(sql), req.query.page, syzoj.config.page.problem); - let problems = await Problem.query(sql + paginate.toSQL() + ` ORDER BY ${sortVal} ${order}`); + let problems = await Problem.query(sql + ` ORDER BY ${sortVal} ${order} ` + paginate.toSQL()); await problems.forEachAsync(async problem => { problem.allowedEdit = await problem.isAllowedEditBy(res.locals.user);