Update ranking.js

main
luoyonghuang 2 months ago
parent 2b465511d1
commit 634077c7e9

@ -1,14 +1,25 @@
const pool = require('../db'); const pool = require('../db');
async function getRanking(req, res) { async function get_descend_Ranking(req, res) {
try { try {
const connection = await pool.getConnection(); const connection = await pool.getConnection();
const [ranking] = await connection.query('SELECT student_name, student_id, score, call_count FROM students ORDER BY score DESC'); const [ranking] = await connection.query('SELECT student_name, student_id, score FROM students ORDER BY score DESC');
connection.release(); connection.release();
res.send({ ranking }); res.json(ranking);
} catch (error) { } catch (error) {
res.status(500).send({ error: '无法获取排名' }); res.status(500).send({ error: '无法获取排名' });
} }
} }
module.exports = { getRanking }; 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 };

Loading…
Cancel
Save