Add composite primary key to player_capes and update messages

Added a composite primary key (playerUuid, assetHash) to the player_capes table for better data integrity. Updated userRepository.js to use English messages for cape assignment and removal operations.
This commit is contained in:
Gilles Lazures 2026-01-18 23:16:11 +01:00
parent 0049ae8ec6
commit 01e0b94d35
3 changed files with 10 additions and 6 deletions

View File

@ -229,6 +229,7 @@ async function setupDatabase() {
assetHash VARCHAR(64) NOT NULL,
isSelected TINYINT(1) DEFAULT 0,
createdAt DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (playerUuid, assetHash),
FOREIGN KEY (playerUuid) REFERENCES players(uuid) ON DELETE CASCADE,
FOREIGN KEY (assetHash) REFERENCES textures(hash) ON DELETE CASCADE
)

View File

@ -63,6 +63,9 @@ function getUrlParam(url, param) {
}
function handleDBError(error, errorMessage = "Internal Server Error", code = 500) {
if (error instanceof DefaultError) {
throw error
}
logger.log(errorMessage.bold + " : " + error.toString(), ["MariaDB", "yellow"])
throw new DefaultError(code, errorMessage, "InternalServerError")
}

View File

@ -666,12 +666,12 @@ async function addCapeToPlayer(uuid, hash) {
const result = await database.query(sql, [uuid, hash])
if (result.affectedRows > 0) {
return { code: 200, message: "Cape accordée au joueur." }
return { code: 200, message: "Cape granted to the player." }
}
throw new DefaultError(500, "Erreur lors de l'attribution de la cape.")
throw new DefaultError(500, "Error when assigning the cape.")
} catch (error) {
if (error.code === 'ER_DUP_ENTRY') {
throw new DefaultError(409, "Le joueur possède déjà cette cape.")
if (error.code === "ER_DUP_ENTRY") {
throw new DefaultError(409, "The player already possesses this cloak.")
}
return utils.handleDBError(error)
}
@ -683,9 +683,9 @@ async function removeCapeFromPlayer(uuid, hash) {
const result = await database.query(sql, [uuid, hash])
if (result.affectedRows > 0) {
return { code: 200, message: "Cape retirée du joueur." }
return { code: 200, message: "Cape removed from player." }
} else {
throw new DefaultError(404, "Le joueur ne possède pas cette cape.")
throw new DefaultError(404, "The player does not own this cloak.")
}
} catch (error) {
return utils.handleDBError(error)