From 6b67287b04878ee69a7a6ecaf75f5515bc9b3677 Mon Sep 17 00:00:00 2001 From: pjmw9izve <2308014474@qq.com> Date: Sun, 6 Oct 2024 13:10:02 +0800 Subject: [PATCH] ADD file via upload --- scoreManager.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 scoreManager.js diff --git a/scoreManager.js b/scoreManager.js new file mode 100644 index 0000000..5aebd1c --- /dev/null +++ b/scoreManager.js @@ -0,0 +1,22 @@ +const pool = require('../db'); + +async function updateScore(req, res) { + const { student_id, points } = req.body; //假设前端发送的数据是这两部分 + + try { + const connection = await pool.getConnection(); + const [result] = await connection.query('UPDATE students SET score = score + ?, call_count = call_count + 1 WHERE student_id = ?', [points, student_id]); + + if (result.affectedRows > 0) { + res.send({ message: '积分已更新' }); + } else { + res.status(404).send({ message: '学生不存在' }); + } + + connection.release(); + } catch (error) { + res.status(500).send({ error: '更新积分失败' }); + } +} + +module.exports = { updateScore };