Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit dd74e7e

Browse files
committed
refactor: Remove transferItem method and related decorators from Items and StripeController
1 parent 26644b1 commit dd74e7e

File tree

5 files changed

+0
-196
lines changed

5 files changed

+0
-196
lines changed

dist/controllers/ItemController.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ export declare class Items {
2121
giveItem(req: AuthenticatedRequestWithOwner, res: Response): Promise<Response<any, Record<string, any>> | undefined>;
2222
consumeItem(req: AuthenticatedRequestWithOwner, res: Response): Promise<Response<any, Record<string, any>> | undefined>;
2323
dropItem(req: AuthenticatedRequest, res: Response): Promise<Response<any, Record<string, any>> | undefined>;
24-
transferItem(req: AuthenticatedRequest, res: Response): Promise<Response<any, Record<string, any>> | undefined>;
2524
transferOwnership(req: AuthenticatedRequestWithOwner, res: Response): Promise<Response<any, Record<string, any>> | undefined>;
2625
}

dist/controllers/ItemController.js

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -294,47 +294,6 @@ let Items = class Items {
294294
res.status(500).send({ message: "Error dropping item", error: message });
295295
}
296296
}
297-
async transferItem(req, res) {
298-
const { itemId } = req.params;
299-
const { amount, targetUserId } = req.body;
300-
if (!itemId || isNaN(amount) || amount <= 0 || !targetUserId) {
301-
return res.status(400).send({ message: "Invalid input" });
302-
}
303-
try {
304-
const user = req.user;
305-
if (!user) {
306-
return res.status(404).send({ message: "User not found" });
307-
}
308-
if (user.user_id === targetUserId) {
309-
return res.status(400).send({ message: "Cannot transfer to yourself" });
310-
}
311-
// Check sender inventory
312-
const senderAmount = await this.inventoryService.getItemAmount(user.user_id, itemId);
313-
if (!senderAmount || senderAmount < amount) {
314-
return res
315-
.status(400)
316-
.send({ message: "Not enough items to transfer" });
317-
}
318-
// Remove from sender
319-
await this.inventoryService.removeItem(user.user_id, itemId, amount);
320-
// Add to recipient
321-
const recipientAmount = await this.inventoryService.getItemAmount(targetUserId, itemId);
322-
if (recipientAmount) {
323-
await this.inventoryService.setItemAmount(targetUserId, itemId, recipientAmount + Number(amount));
324-
}
325-
else {
326-
await this.inventoryService.addItem(targetUserId, itemId, Number(amount));
327-
}
328-
res.status(200).send({ message: "Item transferred" });
329-
}
330-
catch (error) {
331-
console.error("Error transferring item", error);
332-
const message = error instanceof Error ? error.message : String(error);
333-
res
334-
.status(500)
335-
.send({ message: "Error transferring item", error: message });
336-
}
337-
}
338297
async transferOwnership(req, res) {
339298
const { itemId } = req.params;
340299
const { newOwnerId } = req.body;
@@ -588,25 +547,6 @@ __decorate([
588547
__metadata("design:paramtypes", [Object, Object]),
589548
__metadata("design:returntype", Promise)
590549
], Items.prototype, "dropItem", null);
591-
__decorate([
592-
(0, describe_1.describe)({
593-
endpoint: "/items/transfer/:itemId",
594-
method: "POST",
595-
description: "Transfer item occurrences to another user.",
596-
params: { itemId: "The id of the item" },
597-
body: {
598-
amount: "The amount of the item to transfer",
599-
targetUserId: "The user ID of the recipient",
600-
},
601-
responseType: { message: "string" },
602-
example: 'POST /api/items/transfer/item_1 {"amount": 1, "targetUserId": "user_2"}',
603-
requiresAuth: true,
604-
}),
605-
(0, inversify_express_utils_1.httpPost)("/transfer/:itemId", LoggedCheck_1.LoggedCheck.middleware),
606-
__metadata("design:type", Function),
607-
__metadata("design:paramtypes", [Object, Object]),
608-
__metadata("design:returntype", Promise)
609-
], Items.prototype, "transferItem", null);
610550
__decorate([
611551
(0, inversify_express_utils_1.httpPost)("/transfer-ownership/:itemId", OwnerCheck_1.OwnerCheck.middleware),
612552
__metadata("design:type", Function),

dist/controllers/StripeController.js

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ const inversify_express_utils_1 = require("inversify-express-utils");
4343
const stripe_1 = __importDefault(require("stripe"));
4444
const inversify_1 = require("inversify");
4545
const LoggedCheck_1 = require("../middlewares/LoggedCheck");
46-
const describe_1 = require("../decorators/describe");
4746
const yup_1 = require("yup");
4847
const yup = __importStar(require("yup"));
4948
// --- CONSTANTS ---
@@ -115,7 +114,6 @@ let StripeController = class StripeController {
115114
apiVersion: "2025-06-30.basil"
116115
});
117116
}
118-
// --- WEBHOOK ---
119117
async handleWebhook(req, res) {
120118
if (!STRIPE_WEBHOOK_SECRET) {
121119
return handleError(res, new Error("Webhook secret not configured"), "Stripe webhook secret is not set", 500);
@@ -239,47 +237,18 @@ let StripeController = class StripeController {
239237
}
240238
};
241239
__decorate([
242-
(0, describe_1.describe)({
243-
endpoint: "/stripe/webhook",
244-
method: "POST",
245-
description: "Handle Stripe webhook events",
246-
responseType: { received: "boolean" },
247-
example: "POST /api/stripe/webhook"
248-
}),
249240
(0, inversify_express_utils_1.httpPost)("/webhook"),
250241
__metadata("design:type", Function),
251242
__metadata("design:paramtypes", [Object, Object]),
252243
__metadata("design:returntype", Promise)
253244
], StripeController.prototype, "handleWebhook", null);
254245
__decorate([
255-
(0, describe_1.describe)({
256-
endpoint: "/stripe/checkout",
257-
method: "GET",
258-
description: "Create a Stripe checkout session for buying credits",
259-
query: { tier: "The credit tier to purchase (tier1, tier2, tier3, tier4)" },
260-
responseType: { url: "string" },
261-
example: "GET /api/stripe/checkout?tier=tier1",
262-
requiresAuth: true
263-
}),
264246
(0, inversify_express_utils_1.httpGet)("/checkout", LoggedCheck_1.LoggedCheck.middleware),
265247
__metadata("design:type", Function),
266248
__metadata("design:paramtypes", [Object, Object]),
267249
__metadata("design:returntype", Promise)
268250
], StripeController.prototype, "checkoutEndpoint", null);
269251
__decorate([
270-
(0, describe_1.describe)({
271-
endpoint: "/stripe/tiers",
272-
method: "GET",
273-
description: "Get available credit tiers",
274-
responseType: [{
275-
id: "string",
276-
price: "number",
277-
credits: "number",
278-
name: "string",
279-
image: "string"
280-
}],
281-
example: "GET /api/stripe/tiers"
282-
}),
283252
(0, inversify_express_utils_1.httpGet)("/tiers"),
284253
__metadata("design:type", Function),
285254
__metadata("design:paramtypes", [Object, Object]),

src/controllers/ItemController.ts

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -512,79 +512,6 @@ export class Items {
512512
}
513513
}
514514

515-
@describe({
516-
endpoint: "/items/transfer/:itemId",
517-
method: "POST",
518-
description: "Transfer item occurrences to another user.",
519-
params: { itemId: "The id of the item" },
520-
body: {
521-
amount: "The amount of the item to transfer",
522-
targetUserId: "The user ID of the recipient",
523-
},
524-
responseType: { message: "string" },
525-
example:
526-
'POST /api/items/transfer/item_1 {"amount": 1, "targetUserId": "user_2"}',
527-
requiresAuth: true,
528-
})
529-
@httpPost("/transfer/:itemId", LoggedCheck.middleware)
530-
public async transferItem(req: AuthenticatedRequest, res: Response) {
531-
const { itemId } = req.params;
532-
const { amount, targetUserId } = req.body;
533-
if (!itemId || isNaN(amount) || amount <= 0 || !targetUserId) {
534-
return res.status(400).send({ message: "Invalid input" });
535-
}
536-
try {
537-
const user = req.user;
538-
if (!user) {
539-
return res.status(404).send({ message: "User not found" });
540-
}
541-
if (user.user_id === targetUserId) {
542-
return res.status(400).send({ message: "Cannot transfer to yourself" });
543-
}
544-
545-
// Check sender inventory
546-
const senderAmount = await this.inventoryService.getItemAmount(
547-
user.user_id,
548-
itemId
549-
);
550-
if (!senderAmount || senderAmount < amount) {
551-
return res
552-
.status(400)
553-
.send({ message: "Not enough items to transfer" });
554-
}
555-
556-
// Remove from sender
557-
await this.inventoryService.removeItem(user.user_id, itemId, amount);
558-
559-
// Add to recipient
560-
const recipientAmount = await this.inventoryService.getItemAmount(
561-
targetUserId,
562-
itemId
563-
);
564-
if (recipientAmount) {
565-
await this.inventoryService.setItemAmount(
566-
targetUserId,
567-
itemId,
568-
recipientAmount + Number(amount)
569-
);
570-
} else {
571-
await this.inventoryService.addItem(
572-
targetUserId,
573-
itemId,
574-
Number(amount)
575-
);
576-
}
577-
578-
res.status(200).send({ message: "Item transferred" });
579-
} catch (error) {
580-
console.error("Error transferring item", error);
581-
const message = error instanceof Error ? error.message : String(error);
582-
res
583-
.status(500)
584-
.send({ message: "Error transferring item", error: message });
585-
}
586-
}
587-
588515
@httpPost("/transfer-ownership/:itemId", OwnerCheck.middleware)
589516
public async transferOwnership(req: AuthenticatedRequestWithOwner, res: Response) {
590517
const { itemId } = req.params;

src/controllers/StripeController.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Stripe from "stripe";
44
import { inject } from "inversify";
55
import { IUserService } from "../services/UserService";
66
import { AuthenticatedRequest, LoggedCheck } from "../middlewares/LoggedCheck";
7-
import { describe } from "../decorators/describe";
87
import { ValidationError, Schema } from "yup";
98
import * as yup from "yup";
109

@@ -90,14 +89,6 @@ export class StripeController {
9089
});
9190
}
9291

93-
// --- WEBHOOK ---
94-
@describe({
95-
endpoint: "/stripe/webhook",
96-
method: "POST",
97-
description: "Handle Stripe webhook events",
98-
responseType: { received: "boolean" },
99-
example: "POST /api/stripe/webhook"
100-
})
10192
@httpPost("/webhook")
10293
public async handleWebhook(req: Request, res: Response) {
10394
if (!STRIPE_WEBHOOK_SECRET) {
@@ -131,15 +122,6 @@ export class StripeController {
131122
}
132123

133124
// --- CHECKOUT ---
134-
@describe({
135-
endpoint: "/stripe/checkout",
136-
method: "GET",
137-
description: "Create a Stripe checkout session for buying credits",
138-
query: { tier: "The credit tier to purchase (tier1, tier2, tier3, tier4)" },
139-
responseType: { url: "string" },
140-
example: "GET /api/stripe/checkout?tier=tier1",
141-
requiresAuth: true
142-
})
143125
@httpGet("/checkout", LoggedCheck.middleware)
144126
public async checkoutEndpoint(req: AuthenticatedRequest, res: Response) {
145127
if (!(await validateOr400(checkoutQuerySchema, req.query, res))) return;
@@ -170,19 +152,6 @@ export class StripeController {
170152
}
171153
}
172154

173-
@describe({
174-
endpoint: "/stripe/tiers",
175-
method: "GET",
176-
description: "Get available credit tiers",
177-
responseType: [{
178-
id: "string",
179-
price: "number",
180-
credits: "number",
181-
name: "string",
182-
image: "string"
183-
}],
184-
example: "GET /api/stripe/tiers"
185-
})
186155
@httpGet("/tiers")
187156
public async getTiers(req: Request, res: Response) {
188157
res.send(CREDIT_TIERS);

0 commit comments

Comments
 (0)