Skip to content
This repository was archived by the owner on Apr 8, 2026. It is now read-only.

Commit e7396b9

Browse files
committed
Refactor UserController and WebAuthnController for improved logging and error handling
- Updated logging statements to use consistent quotation marks. - Simplified error handling in WebAuthnController for generating registration and authentication options. - Enhanced readability by removing unnecessary line breaks in response handling. - Added console logs in InventoryRepository for better debugging during item removal. - Adjusted SQL queries in InventoryRepository to ensure precise stack deletion and updates. - Commented code for clarity on inventory operations. - Commented out error logging during database backup to reduce noise in logs.
1 parent d68a0d4 commit e7396b9

19 files changed

Lines changed: 712 additions & 718 deletions

dist/controllers/AuthenticatorController.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ let Authenticator = class Authenticator {
6868
http_method: req.method,
6969
request_body: requestBody,
7070
user_id: req.user?.user_id,
71-
status_code: statusCode
71+
status_code: statusCode,
7272
});
7373
}
7474
catch (error) {
75-
console.error('Error creating log:', error);
75+
console.error("Error creating log:", error);
7676
}
7777
}
7878
async generateKey(req, res) {

dist/controllers/BuyOrderController.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ let BuyOrderController = class BuyOrderController {
4242
http_method: req.method,
4343
request_body: requestBody,
4444
user_id: req.user?.user_id,
45-
status_code: statusCode
45+
status_code: statusCode,
4646
});
4747
}
4848
catch (error) {
49-
console.error('Error creating log:', error);
49+
console.error("Error creating log:", error);
5050
}
5151
}
5252
async createBuyOrder(req, res) {

dist/controllers/GameController.js

Lines changed: 63 additions & 60 deletions
Large diffs are not rendered by default.

dist/controllers/GameGiftController.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -39,35 +39,35 @@ let GameGifts = class GameGifts {
3939
http_method: req.method,
4040
request_body: req.body,
4141
user_id: userId,
42-
status_code: statusCode
42+
status_code: statusCode,
4343
});
4444
}
4545
catch (error) {
46-
console.error('Error creating log:', error);
46+
console.error("Error creating log:", error);
4747
}
4848
}
4949
async createGift(req, res) {
5050
const { gameId, message } = req.body;
5151
const userId = req.user.user_id;
5252
if (!gameId) {
53-
await this.createLog(req, 'createGift', 'gifts', 400, userId);
53+
await this.createLog(req, "createGift", "gifts", 400, userId);
5454
return res.status(400).send({ message: "Game ID is required" });
5555
}
5656
try {
5757
const game = await this.gameService.getGame(gameId);
5858
if (!game) {
59-
await this.createLog(req, 'createGift', 'gifts', 404, userId);
59+
await this.createLog(req, "createGift", "gifts", 404, userId);
6060
return res.status(404).send({ message: "Game not found" });
6161
}
6262
const user = await this.userService.getUser(userId);
6363
if (!user) {
64-
await this.createLog(req, 'createGift', 'gifts', 404, userId);
64+
await this.createLog(req, "createGift", "gifts", 404, userId);
6565
return res.status(404).send({ message: "User not found" });
6666
}
6767
if (user.balance < game.price) {
68-
await this.createLog(req, 'createGift', 'gifts', 400, userId);
68+
await this.createLog(req, "createGift", "gifts", 400, userId);
6969
return res.status(400).send({
70-
message: `Insufficient balance. Required: ${game.price}, Available: ${user.balance}`
70+
message: `Insufficient balance. Required: ${game.price}, Available: ${user.balance}`,
7171
});
7272
}
7373
if (userId !== game.owner_id) {
@@ -78,51 +78,51 @@ let GameGifts = class GameGifts {
7878
}
7979
}
8080
const gift = await this.giftService.createGift(gameId, userId, message);
81-
await this.createLog(req, 'createGift', 'gifts', 201, userId);
81+
await this.createLog(req, "createGift", "gifts", 201, userId);
8282
res.status(201).send({
8383
message: "Gift created successfully",
8484
gift: {
8585
id: gift.id,
8686
gameId: gift.gameId,
8787
giftCode: gift.giftCode,
8888
createdAt: gift.createdAt,
89-
message: gift.message
90-
}
89+
message: gift.message,
90+
},
9191
});
9292
}
9393
catch (error) {
94-
await this.createLog(req, 'createGift', 'gifts', 500, userId);
94+
await this.createLog(req, "createGift", "gifts", 500, userId);
9595
handleError(res, error, "Error creating gift");
9696
}
9797
}
9898
async claimGift(req, res) {
9999
const { giftCode } = req.body;
100100
const userId = req.user.user_id;
101101
if (!giftCode) {
102-
await this.createLog(req, 'claimGift', 'gifts', 400, userId);
102+
await this.createLog(req, "claimGift", "gifts", 400, userId);
103103
return res.status(400).send({ message: "Gift code is required" });
104104
}
105105
try {
106106
const gift = await this.giftService.getGift(giftCode);
107107
if (!gift) {
108-
await this.createLog(req, 'claimGift', 'gifts', 404, userId);
108+
await this.createLog(req, "claimGift", "gifts", 404, userId);
109109
return res.status(404).send({ message: "Invalid gift code" });
110110
}
111111
const userOwnsGame = await this.gameService.userOwnsGame(gift.gameId, userId);
112112
if (userOwnsGame) {
113-
await this.createLog(req, 'claimGift', 'gifts', 400, userId);
113+
await this.createLog(req, "claimGift", "gifts", 400, userId);
114114
return res.status(400).send({ message: "You already own this game" });
115115
}
116116
const claimedGift = await this.giftService.claimGift(giftCode, userId);
117117
await this.gameService.addOwner(gift.gameId, userId);
118-
await this.createLog(req, 'claimGift', 'gifts', 200, userId);
118+
await this.createLog(req, "claimGift", "gifts", 200, userId);
119119
res.status(200).send({
120120
message: "Gift claimed successfully",
121-
gift: claimedGift
121+
gift: claimedGift,
122122
});
123123
}
124124
catch (error) {
125-
await this.createLog(req, 'claimGift', 'gifts', 400, userId);
125+
await this.createLog(req, "claimGift", "gifts", 400, userId);
126126
handleError(res, error, "Error claiming gift", 400);
127127
}
128128
}
@@ -133,14 +133,14 @@ let GameGifts = class GameGifts {
133133
const game = await this.gameService.getGameForPublic(gift.gameId);
134134
return {
135135
...gift,
136-
game
136+
game,
137137
};
138138
}));
139-
await this.createLog(req, 'getSentGifts', 'gifts', 200, req.user.user_id);
139+
await this.createLog(req, "getSentGifts", "gifts", 200, req.user.user_id);
140140
res.send(enrichedGifts);
141141
}
142142
catch (error) {
143-
await this.createLog(req, 'getSentGifts', 'gifts', 500, req.user.user_id);
143+
await this.createLog(req, "getSentGifts", "gifts", 500, req.user.user_id);
144144
handleError(res, error, "Error fetching sent gifts");
145145
}
146146
}
@@ -153,14 +153,14 @@ let GameGifts = class GameGifts {
153153
return {
154154
...gift,
155155
game,
156-
fromUser: fromUser ? { id: fromUser.user_id, username: fromUser.username } : null
156+
fromUser: fromUser ? { id: fromUser.user_id, username: fromUser.username } : null,
157157
};
158158
}));
159-
await this.createLog(req, 'getReceivedGifts', 'gifts', 200, req.user.user_id);
159+
await this.createLog(req, "getReceivedGifts", "gifts", 200, req.user.user_id);
160160
res.send(enrichedGifts);
161161
}
162162
catch (error) {
163-
await this.createLog(req, 'getReceivedGifts', 'gifts', 500, req.user.user_id);
163+
await this.createLog(req, "getReceivedGifts", "gifts", 500, req.user.user_id);
164164
handleError(res, error, "Error fetching received gifts");
165165
}
166166
}
@@ -169,29 +169,29 @@ let GameGifts = class GameGifts {
169169
try {
170170
const gift = await this.giftService.getGift(giftCode);
171171
if (!gift) {
172-
await this.createLog(req, 'getGiftInfo', 'gifts', 404, req.user.user_id);
172+
await this.createLog(req, "getGiftInfo", "gifts", 404, req.user.user_id);
173173
return res.status(404).send({ message: "Gift not found" });
174174
}
175175
const game = await this.gameService.getGameForPublic(gift.gameId);
176176
const fromUser = await this.userService.getUser(gift.fromUserId);
177177
const userOwnsGame = await this.gameService.userOwnsGame(gift.gameId, req.user.user_id);
178-
await this.createLog(req, 'getGiftInfo', 'gifts', 200, req.user.user_id);
178+
await this.createLog(req, "getGiftInfo", "gifts", 200, req.user.user_id);
179179
res.send({
180180
gift: {
181181
gameId: gift.gameId,
182182
giftCode: gift.giftCode,
183183
createdAt: gift.createdAt,
184184
claimedAt: gift.claimedAt,
185185
isActive: gift.isActive,
186-
message: gift.message
186+
message: gift.message,
187187
},
188188
game,
189189
fromUser: fromUser ? { id: fromUser.user_id, username: fromUser.username } : null,
190-
userOwnsGame
190+
userOwnsGame,
191191
});
192192
}
193193
catch (error) {
194-
await this.createLog(req, 'getGiftInfo', 'gifts', 500, req.user.user_id);
194+
await this.createLog(req, "getGiftInfo", "gifts", 500, req.user.user_id);
195195
handleError(res, error, "Error fetching gift info");
196196
}
197197
}
@@ -200,13 +200,13 @@ let GameGifts = class GameGifts {
200200
const userId = req.user.user_id;
201201
try {
202202
const gifts = await this.giftService.getUserSentGifts(userId);
203-
const gift = gifts.find(g => g.id === giftId);
203+
const gift = gifts.find((g) => g.id === giftId);
204204
if (!gift) {
205-
await this.createLog(req, 'revokeGift', 'gifts', 404, userId);
205+
await this.createLog(req, "revokeGift", "gifts", 404, userId);
206206
return res.status(404).send({ message: "Gift not found" });
207207
}
208208
if (!gift.isActive) {
209-
await this.createLog(req, 'revokeGift', 'gifts', 400, userId);
209+
await this.createLog(req, "revokeGift", "gifts", 400, userId);
210210
return res.status(400).send({ message: "Gift is no longer active" });
211211
}
212212
await this.giftService.revokeGift(giftId, userId);
@@ -221,11 +221,11 @@ let GameGifts = class GameGifts {
221221
await this.userService.updateUserBalance(game.owner_id, owner.balance - game.price * 0.75);
222222
}
223223
}
224-
await this.createLog(req, 'revokeGift', 'gifts', 200, userId);
224+
await this.createLog(req, "revokeGift", "gifts", 200, userId);
225225
res.send({ message: "Gift revoked successfully and refund processed" });
226226
}
227227
catch (error) {
228-
await this.createLog(req, 'revokeGift', 'gifts', 400, userId);
228+
await this.createLog(req, "revokeGift", "gifts", 400, userId);
229229
handleError(res, error, "Error revoking gift", 400);
230230
}
231231
}

dist/controllers/InventoryController.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,46 +56,46 @@ let Inventories = class Inventories {
5656
http_method: req.method,
5757
request_body: req.body,
5858
user_id: userId,
59-
status_code: statusCode
59+
status_code: statusCode,
6060
});
6161
}
6262
catch (error) {
63-
console.error('Error creating log:', error);
63+
console.error("Error creating log:", error);
6464
}
6565
}
6666
// --- Inventaire de l'utilisateur courant ---
6767
async getMyInventory(req, res) {
6868
const userId = req.user.user_id;
6969
try {
7070
const inventory = await this.inventoryService.getInventory(userId);
71-
await this.createLog(req, 'getMyInventory', 'inventory', 200, userId);
71+
await this.createLog(req, "getMyInventory", "inventory", 200, userId);
7272
res.send(inventory);
7373
}
7474
catch (error) {
75-
await this.createLog(req, 'getMyInventory', 'inventory', 500, userId);
75+
await this.createLog(req, "getMyInventory", "inventory", 500, userId);
7676
handleError(res, error, "Error fetching inventory");
7777
}
7878
}
7979
// --- Inventaire d'un utilisateur spécifique ---
8080
async getInventory(req, res) {
8181
if (!(await validateOr400(InventoryValidator_1.userIdParamSchema, { userId: req.params.userId }, res))) {
82-
await this.createLog(req, 'getInventory', 'inventory', 400, req.params.userId);
82+
await this.createLog(req, "getInventory", "inventory", 400, req.params.userId);
8383
return;
8484
}
8585
const userId = req.params.userId;
8686
try {
8787
const inventory = await this.inventoryService.getInventory(userId);
88-
await this.createLog(req, 'getInventory', 'inventory', 200, userId);
88+
await this.createLog(req, "getInventory", "inventory", 200, userId);
8989
res.send(inventory);
9090
}
9191
catch (error) {
92-
await this.createLog(req, 'getInventory', 'inventory', 500, userId);
92+
await this.createLog(req, "getInventory", "inventory", 500, userId);
9393
handleError(res, error, "Error fetching inventory");
9494
}
9595
}
9696
// --- Route générique (prompt) ---
9797
async getAllInventories(req, res) {
98-
await this.createLog(req, 'getAllInventories', 'inventory', 400);
98+
await this.createLog(req, "getAllInventories", "inventory", 400);
9999
res.send({ message: "Please specify /api/inventory/<userId>" });
100100
}
101101
};
@@ -121,9 +121,9 @@ __decorate([
121121
iconHash: "string",
122122
price: "number",
123123
owner: "string",
124-
showInStore: "boolean"
125-
}
126-
]
124+
showInStore: "boolean",
125+
},
126+
],
127127
},
128128
example: "GET /api/inventory/@me",
129129
requiresAuth: true,
@@ -155,9 +155,9 @@ __decorate([
155155
iconHash: "string",
156156
price: "number",
157157
owner: "string",
158-
showInStore: "boolean"
159-
}
160-
]
158+
showInStore: "boolean",
159+
},
160+
],
161161
},
162162
example: "GET /api/inventory/123",
163163
}),

0 commit comments

Comments
 (0)