Refactor skin selection logic and remove DB trigger
Removed the 'unique_active_skin' database trigger from setupDatabase and updated setSkin in userRepository to handle skin selection logic in application code. This change centralizes the logic for ensuring only one active skin per user, improving maintainability and error handling.
This commit is contained in:
@@ -656,19 +656,21 @@ async function getNameHistory(uuid) {
|
||||
}
|
||||
|
||||
async function setSkin(uuid, hash, variant) {
|
||||
const insertSql = `
|
||||
INSERT INTO playersSkins (playerUuid, assetHash, variant, isSelected)
|
||||
VALUES (?, ?, ?, 1)
|
||||
ON DUPLICATE KEY UPDATE isSelected = 1, variant = ?
|
||||
`
|
||||
await database.query(insertSql, [uuid, hash, variant, variant])
|
||||
const updateSql = `
|
||||
UPDATE playersSkins
|
||||
SET isSelected = 0
|
||||
WHERE playerUuid = ? AND assetHash != ?
|
||||
`
|
||||
await database.query(updateSql, [uuid, hash])
|
||||
return true
|
||||
try {
|
||||
const resetSql = `UPDATE playersSkins SET isSelected = 0 WHERE playerUuid = ?`
|
||||
await database.query(resetSql, [uuid])
|
||||
|
||||
const upsertSql = `
|
||||
INSERT INTO playersSkins (playerUuid, assetHash, variant, isSelected)
|
||||
VALUES (?, ?, ?, 1)
|
||||
ON DUPLICATE KEY UPDATE isSelected = 1, variant = VALUES(variant)
|
||||
`
|
||||
await database.query(upsertSql, [uuid, hash, variant.toLowerCase()])
|
||||
|
||||
return true
|
||||
} catch (error) {
|
||||
return utils.handleDBError(error)
|
||||
}
|
||||
}
|
||||
|
||||
async function updatePassword(uuid, hashedPassword) {
|
||||
|
||||
Reference in New Issue
Block a user