diff --git a/modules/databaseGlobals.js b/modules/databaseGlobals.js index 66be05c..4c36ee7 100644 --- a/modules/databaseGlobals.js +++ b/modules/databaseGlobals.js @@ -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 ) diff --git a/modules/utils.js b/modules/utils.js index 354ae0d..438844a 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -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") } diff --git a/repositories/userRepository.js b/repositories/userRepository.js index 3d019ba..3eb4b59 100644 --- a/repositories/userRepository.js +++ b/repositories/userRepository.js @@ -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)