Refactor cape selection logic and remove trigger
Removed the 'unique_active_cape' database trigger and updated the showCape function to manually ensure only one cape is selected per player. This change centralizes the selection logic in application code for better maintainability and error handling.
This commit is contained in:
@@ -416,15 +416,19 @@ async function hideCape(uuid) {
|
||||
|
||||
async function showCape(uuid, hash) {
|
||||
try {
|
||||
const sql = `
|
||||
UPDATE playersCapes
|
||||
SET isSelected = (assetHash = ?)
|
||||
WHERE playerUuid = ?
|
||||
`
|
||||
const result = await database.query(sql, [hash, uuid])
|
||||
return { code: 200, changed: result.affectedRows > 0 }
|
||||
await database.query(
|
||||
"UPDATE playersCapes SET isSelected = 0 WHERE playerUuid = ?",
|
||||
[uuid]
|
||||
)
|
||||
|
||||
const [res] = await database.query(
|
||||
"UPDATE playersCapes SET isSelected = 1 WHERE playerUuid = ? AND assetHash = ?",
|
||||
[uuid, hash]
|
||||
)
|
||||
|
||||
return { code: 200, changed: res.affectedRows > 0 }
|
||||
} catch (error) {
|
||||
logger.log("Internal Server Error".bold + " : " + error.toString(), ["MariaDB", "yellow"])
|
||||
logger.log("Database Error: " + error.toString(), ["MariaDB", "red"])
|
||||
throw new DefaultError(500, "Internal Server Error", "Database Error")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user