You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
757 B

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 };