import { Controller, Get, Param, ParseUUIDPipe, Post, Query } from '@nestjs/common'; import { CurrentSession } from '../auth/session.decorator'; import type { AuthenticatedSession } from '../auth/tenant.guard'; import { SagasService } from './sagas.service'; const STATUSES = [ 'RUNNING', 'COMPLETED', 'COMPENSATING', 'COMPENSATED', 'FAILED', 'TIMED_OUT', ] as const; @Controller('sagas') export class SagasController { constructor(private readonly sagas: SagasService) {} @Get() overview(@CurrentSession() session: AuthenticatedSession) { return this.sagas.overview(session); } @Get('instances') list(@CurrentSession() session: AuthenticatedSession, @Query('status') status?: string) { // Allowlist, nu interpolare: statusul ajunge intr-o comparatie SQL. const safe = STATUSES.includes(status as (typeof STATUSES)[number]) ? status : undefined; return this.sagas.list(session, safe); } @Get('instances/:id') detail(@CurrentSession() session: AuthenticatedSession, @Param('id', ParseUUIDPipe) id: string) { return this.sagas.detail(session, id); } @Post('instances/:id/retry') retry(@CurrentSession() session: AuthenticatedSession, @Param('id', ParseUUIDPipe) id: string) { return this.sagas.retry(session, id); } }