import { Body, Controller, Delete, Get, HttpCode, Param, Post, Query } from '@nestjs/common'; import { RoutesService } from './routes.service'; import { CurrentTenantContext } from '../auth/current-tenant.decorator'; import { TenantContext } from '../../common/tenant-context'; import { IsString } from 'class-validator'; class CreateRouteDto { @IsString() sourceGroupId!: string; @IsString() targetGroupId!: string; } class BatchCreateRouteDto { @IsString() sourceGroupId!: string; @IsString({ each: true }) targetGroupIds!: string[]; } @Controller('routes') export class RoutesController { constructor(private readonly routesService: RoutesService) {} @Get() list( @CurrentTenantContext() ctx: TenantContext, @Query('sourceGroupId') sourceGroupId?: string, ) { return this.routesService.list(ctx.tenantId, sourceGroupId); } @Post() create(@CurrentTenantContext() ctx: TenantContext, @Body() body: CreateRouteDto) { return this.routesService.create(ctx.tenantId, body.sourceGroupId, body.targetGroupId); } @Post('batch') createBatch(@CurrentTenantContext() ctx: TenantContext, @Body() body: BatchCreateRouteDto) { return this.routesService.createBatch(ctx.tenantId, body.sourceGroupId, body.targetGroupIds); } @Delete(':id') @HttpCode(204) async remove(@CurrentTenantContext() ctx: TenantContext, @Param('id') id: string) { await this.routesService.remove(ctx.tenantId, id); } }