MonEspacePro/backend/src/counter/counter.controller.ts
Tony AVERTY bf10beb89b Inscription en ligne automatique, rôle Dirigeant, cadeaux en nature, titre des campagnes
- Inscription depuis la page Tarif : paiement Stripe puis création automatique
  du magasin, de l'abonnement et du compte Dirigeant (webhook), e-mail de bienvenue
- Plus d'essai gratuit (site, Stripe, e-mails)
- Création d'un magasin dans l'admin : formule obligatoire, compte Dirigeant et
  lien de paiement permanent envoyés automatiquement
- Ouverture automatique du magasin dès l'abonnement payé et la carte conçue
- API du Dirigeant : carte, employés, fiche magasin ; changement de mot de passe
- Anniversaire et parrainage : cadeau en nature remis en caisse
- Campagnes : titre de notification choisi à chaque envoi
- « Gérant » devient « Dirigeant »

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 11:45:07 +02:00

76 lines
2.3 KiB
TypeScript

import { Body, Controller, Get, HttpCode, Param, Post, Query, UseGuards } from '@nestjs/common';
import { Throttle } from '@nestjs/throttler';
import { IsIn, IsInt, IsOptional, IsString, Max, Min } from 'class-validator';
import { CurrentUser, JwtAuthGuard, StaffGuard } from '../common/guards';
import { JwtPayload } from '../common/auth.types';
import { CounterService, StaffContext } from './counter.service';
class CreditDto {
/** Absent en mode tampons. */
@IsOptional() @IsInt() @Min(1) @Max(1_000_000)
amountCents?: number;
}
class RedeemDto {
@IsString()
rewardId!: string;
}
class HistoryQuery {
@IsOptional() @IsIn(['today', 'week'])
period?: 'today' | 'week';
@IsOptional() @IsString()
cursor?: string;
}
function ctx(user: JwtPayload): StaffContext {
if (user.kind !== 'staff') throw new Error('StaffGuard manquant');
return { staffId: user.sub, storeId: user.storeId, role: user.role };
}
/** API de l'app Pro (employés au comptoir). */
@Controller('staff')
@UseGuards(JwtAuthGuard, StaffGuard)
export class CounterController {
constructor(private counter: CounterService) {}
@Get('me')
me(@CurrentUser() user: JwtPayload) {
return this.counter.me(ctx(user));
}
@Get('summary')
summary(@CurrentUser() user: JwtPayload) {
return this.counter.summary(ctx(user));
}
@Get('cards/:serial')
@Throttle({ default: { limit: 60, ttl: 60_000 } })
lookup(@CurrentUser() user: JwtPayload, @Param('serial') serial: string) {
return this.counter.lookup(ctx(user), serial);
}
@Post('cards/:serial/credit')
@HttpCode(200)
credit(@CurrentUser() user: JwtPayload, @Param('serial') serial: string, @Body() dto: CreditDto) {
return this.counter.credit(ctx(user), serial, dto.amountCents);
}
@Post('cards/:serial/redeem')
@HttpCode(200)
redeem(@CurrentUser() user: JwtPayload, @Param('serial') serial: string, @Body() dto: RedeemDto) {
return this.counter.redeem(ctx(user), serial, dto.rewardId);
}
@Post('cards/:serial/gifts/:giftId/use')
@HttpCode(200)
useGift(@CurrentUser() user: JwtPayload, @Param('serial') serial: string, @Param('giftId') giftId: string) {
return this.counter.useGift(ctx(user), serial, giftId);
}
@Get('transactions')
history(@CurrentUser() user: JwtPayload, @Query() q: HistoryQuery) {
return this.counter.history(ctx(user), q.period ?? 'today', q.cursor);
}
}