games_app/backend/src/controllers/testWalletController.ts
2026-06-29 15:01:23 +02:00

60 lines
2.0 KiB
TypeScript

import { Response } from 'express';
import { AuthRequest } from '../middleware/auth';
import * as testWalletService from '../services/testWalletService';
export async function getTestWalletStatus(req: AuthRequest, res: Response): Promise<void> {
try {
const status = await testWalletService.getUserTestWalletStatus(req.user!.userId);
res.json(status);
} catch (e) {
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed' });
}
}
export async function requestTestCredits(req: AuthRequest, res: Response): Promise<void> {
try {
const result = await testWalletService.requestTestCredits(req.user!.userId);
res.json(result);
} catch (e) {
const msg = e instanceof Error ? e.message : 'Request failed';
res.status(400).json({ error: msg });
}
}
export async function getAdminConfig(_req: AuthRequest, res: Response): Promise<void> {
try {
const config = await testWalletService.getSettingsForAdmin();
res.json(config);
} catch (e) {
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed' });
}
}
export async function updateAdminConfig(req: AuthRequest, res: Response): Promise<void> {
try {
const body = req.body as {
enabled?: boolean;
creditAmountRaw?: string;
maxRequestsPerUser?: number;
cooldownHours?: number;
walletTypeId?: number;
};
const config = await testWalletService.updateSettings(body);
res.json(config);
} catch (e) {
res.status(400).json({ error: e instanceof Error ? e.message : 'Update failed' });
}
}
export async function listAdminCredits(req: AuthRequest, res: Response): Promise<void> {
try {
const userId = (req.query.userId as string) || undefined;
const limit = Math.min(parseInt((req.query.limit as string) || '50', 10), 200);
const offset = parseInt((req.query.offset as string) || '0', 10);
const result = await testWalletService.listCreditHistory({ userId, limit, offset });
res.json(result);
} catch (e) {
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed' });
}
}