parent
c136816000
commit
6b67287b04
@ -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 };
|
Loading…
Reference in new issue