新增得獎更新、刪除的功能

This commit is contained in:
2025-09-29 22:52:53 +08:00
parent 57893128b2
commit ea6afb1675
6 changed files with 367 additions and 112 deletions

View File

@@ -4676,7 +4676,17 @@ export class AwardService extends DatabaseServiceBase {
if (fields.length === 0) return true;
const setClause = fields.map(field => `${field} = ?`).join(', ');
// 處理 MySQL 保留字,需要用反引號包圍
const setClause = fields.map(field => {
// 將駝峰命名轉換為下劃線命名,並處理保留字
const dbField = field.replace(/([A-Z])/g, '_$1').toLowerCase();
const reservedWords = ['rank', 'order', 'group', 'select', 'from', 'where', 'table'];
if (reservedWords.includes(dbField)) {
return `\`${dbField}\` = ?`;
}
return `${dbField} = ?`;
}).join(', ');
const values = fields.map(field => (updates as any)[field]);
const sql = `UPDATE awards SET ${setClause} WHERE id = ?`;