Files
liqa/server/src/environment/environment.controller.ts
T
ars9 ad155e269c feat(table,runs,sessions): add server-side sorting and pagination
- add sortable column support to Table with asc/desc/unsorted icons
- active sort icon uses --color-primary; no header background change
- Table supports server-side mode via total/page/onPageChange props
- wire server-side sort+pagination in ScenariosPage, AllRunsPage, RunsPage, SessionsPage
- remove steps count column from run tables
- fix server: RunsQueryDto now extends PaginationQueryDto with orderBy/orderDir
- fix findAllRuns to use QueryBuilder; sort by scenario.name via JOIN
- add per-resource typed query DTOs with @IsIn allowlist on orderBy
- prevents SQL injection and returns 400 for unknown orderBy values
2026-04-15 12:18:47 +03:00

84 lines
2.9 KiB
TypeScript

import {
Body,
Controller,
Delete,
Get,
HttpCode,
Param,
ParseUUIDPipe,
Patch,
Post,
Query,
} from "@nestjs/common";
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
import { EnvironmentQueryDto } from "./dto/environment-query.dto";
import { CreateEnvironmentDto } from "./dto/create-environment.dto";
import { EnvironmentExportDto } from "./dto/environment-export.dto";
import { UpdateEnvironmentDto } from "./dto/update-environment.dto";
import { EnvironmentService } from "./environment.service";
@ApiTags("environments")
@Controller("environments")
export class EnvironmentController {
constructor(private readonly environmentService: EnvironmentService) {}
@Post()
@ApiOperation({ summary: "Create a new environment" })
@ApiResponse({ status: 201, description: "Environment created" })
@ApiResponse({ status: 409, description: "Environment name already exists" })
create(@Body() dto: CreateEnvironmentDto) {
return this.environmentService.create(dto);
}
@Post("import")
@ApiOperation({ summary: "Import an environment (upsert by id or name)" })
@ApiResponse({ status: 201, description: "Environment imported" })
async importEnvironment(@Body() dto: EnvironmentExportDto) {
return this.environmentService.importEnvironment(dto);
}
@Get()
@ApiOperation({ summary: "List all environments (paginated)" })
@ApiResponse({ status: 200, description: "Paginated environments" })
findAll(@Query() query: EnvironmentQueryDto) {
return this.environmentService.findAll(query);
}
@Get(":id/export")
@ApiOperation({ summary: "Export an environment as a plain object" })
@ApiResponse({ status: 200, description: "Environment export payload" })
@ApiResponse({ status: 404, description: "Environment not found" })
async exportEnvironment(@Param("id", ParseUUIDPipe) id: string) {
const env = await this.environmentService.findOne(id);
return this.environmentService.exportEnvironment(env);
}
@Get(":id")
@ApiOperation({ summary: "Get environment by ID" })
@ApiResponse({ status: 200, description: "Environment record" })
@ApiResponse({ status: 404, description: "Environment not found" })
findOne(@Param("id", ParseUUIDPipe) id: string) {
return this.environmentService.findOne(id);
}
@Patch(":id")
@ApiOperation({ summary: "Update an environment" })
@ApiResponse({ status: 200, description: "Environment updated" })
@ApiResponse({ status: 404, description: "Environment not found" })
update(
@Param("id", ParseUUIDPipe) id: string,
@Body() dto: UpdateEnvironmentDto,
) {
return this.environmentService.update(id, dto);
}
@Delete(":id")
@HttpCode(204)
@ApiOperation({ summary: "Delete an environment" })
@ApiResponse({ status: 204, description: "Environment deleted" })
@ApiResponse({ status: 404, description: "Environment not found" })
remove(@Param("id", ParseUUIDPipe) id: string) {
return this.environmentService.remove(id);
}
}