import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common'; import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; import { WalletService } from './wallet.service'; import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard'; import { CurrentUser, AuthUser } from '../auth/decorators/current-user.decorator'; @ApiTags('wallet') @ApiBearerAuth() @UseGuards(JwtAuthGuard) @Controller('wallet') export class WalletController { constructor(private readonly wallet: WalletService) {} @Get() async me(@CurrentUser() user: AuthUser) { return this.wallet.getOrCreate(user.tenantId, user.userId); } @Get('transactions') async history(@CurrentUser() user: AuthUser) { const w = await this.wallet.getOrCreate(user.tenantId, user.userId); return this.wallet.history(user.tenantId, w.id); } // شحن ذاتي تجريبي (كاش-إن). للإنتاج يُربط بمزوّد دفع أو يُقيَّد للأدمن. @Post('topup') topup(@CurrentUser() user: AuthUser, @Body('amount') amount: number) { return this.wallet.credit(user.tenantId, user.userId, Number(amount), 'topup'); } }