good forst commit
This commit is contained in:
@@ -1,23 +1,44 @@
|
||||
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(@Query('sourceGroupId') sourceGroupId?: string) {
|
||||
return this.routesService.list(sourceGroupId);
|
||||
list(
|
||||
@CurrentTenantContext() ctx: TenantContext,
|
||||
@Query('sourceGroupId') sourceGroupId?: string,
|
||||
) {
|
||||
return this.routesService.list(ctx.tenantId, sourceGroupId);
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() body: { sourceGroupId: string; targetGroupId: string }) {
|
||||
return this.routesService.create(body.sourceGroupId, body.targetGroupId);
|
||||
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)
|
||||
remove(@Param('id') id: string) {
|
||||
return this.routesService.remove(id);
|
||||
async remove(@CurrentTenantContext() ctx: TenantContext, @Param('id') id: string) {
|
||||
await this.routesService.remove(ctx.tenantId, id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user