From 634077c7e91bdb302f68a14922c74750ad89d9b5 Mon Sep 17 00:00:00 2001 From: luoyonghuang <2308014474@qq.com> Date: Mon, 7 Oct 2024 22:23:06 +0800 Subject: [PATCH] Update ranking.js --- ranking.js | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/ranking.js b/ranking.js index 1b2a6b5..9b0b4ae 100644 --- a/ranking.js +++ b/ranking.js @@ -1,14 +1,25 @@ -const pool = require('../db'); - -async function getRanking(req, res) { - try { - const connection = await pool.getConnection(); - const [ranking] = await connection.query('SELECT student_name, student_id, score, call_count FROM students ORDER BY score DESC'); - connection.release(); - res.send({ ranking }); - } catch (error) { - res.status(500).send({ error: '无法获取排名' }); - } -} - -module.exports = { getRanking }; +const pool = require('../db'); + +async function get_descend_Ranking(req, res) { + try { + const connection = await pool.getConnection(); + const [ranking] = await connection.query('SELECT student_name, student_id, score FROM students ORDER BY score DESC'); + connection.release(); + res.json(ranking); + } catch (error) { + res.status(500).send({ error: '无法获取排名' }); + } +} + +async function get_ascend_Ranking(req, res) { + try { + const connection = await pool.getConnection(); + const [ranking] = await connection.query('SELECT student_name, student_id, score FROM students ORDER BY score ASC'); + connection.release(); + res.json(ranking); + } catch (error) { + res.status(500).send({ error: '无法获取排名' }); + } +} + +module.exports = { get_ascend_Ranking, get_descend_Ranking };