- 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
85 lines
2.8 KiB
TypeScript
85 lines
2.8 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
HttpCode,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
} from "@nestjs/common";
|
|
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
|
|
import { SnippetQueryDto } from "./dto/snippet-query.dto";
|
|
import { CreateSnippetDto } from "./dto/create-snippet.dto";
|
|
import { SnippetExportDto } from "./dto/snippet-export.dto";
|
|
import { UpdateSnippetDto } from "./dto/update-snippet.dto";
|
|
import { SnippetService } from "./snippet.service";
|
|
|
|
@ApiTags("snippets")
|
|
@Controller("snippets")
|
|
export class SnippetController {
|
|
constructor(private readonly snippetService: SnippetService) {}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: "Create a new snippet" })
|
|
@ApiResponse({ status: 201, description: "Snippet created" })
|
|
@ApiResponse({ status: 409, description: "Alias already taken" })
|
|
create(@Body() dto: CreateSnippetDto) {
|
|
return this.snippetService.create(dto);
|
|
}
|
|
|
|
@Post("import")
|
|
@ApiOperation({ summary: "Import a snippet (upsert by id)" })
|
|
@ApiResponse({ status: 201, description: "Snippet imported" })
|
|
async importSnippet(@Body() dto: SnippetExportDto) {
|
|
return this.snippetService.importSnippet(dto);
|
|
}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: "List all snippets (paginated)" })
|
|
@ApiResponse({ status: 200, description: "Paginated snippets" })
|
|
findAll(@Query() query: SnippetQueryDto) {
|
|
return this.snippetService.findAll(query);
|
|
}
|
|
|
|
@Get(":id/export")
|
|
@ApiOperation({ summary: "Export a snippet as a plain object" })
|
|
@ApiResponse({ status: 200, description: "Snippet export payload" })
|
|
@ApiResponse({ status: 404, description: "Snippet not found" })
|
|
async exportSnippet(@Param("id", ParseUUIDPipe) id: string) {
|
|
const snippet = await this.snippetService.findOne(id);
|
|
return this.snippetService.exportSnippet(snippet);
|
|
}
|
|
|
|
@Get(":id")
|
|
@ApiOperation({ summary: "Get snippet by ID" })
|
|
@ApiResponse({ status: 200, description: "Snippet record" })
|
|
@ApiResponse({ status: 404, description: "Snippet not found" })
|
|
findOne(@Param("id", ParseUUIDPipe) id: string) {
|
|
return this.snippetService.findOne(id);
|
|
}
|
|
|
|
@Patch(":id")
|
|
@ApiOperation({ summary: "Update a snippet" })
|
|
@ApiResponse({ status: 200, description: "Snippet updated" })
|
|
@ApiResponse({ status: 404, description: "Snippet not found" })
|
|
@ApiResponse({ status: 409, description: "Alias already taken" })
|
|
update(
|
|
@Param("id", ParseUUIDPipe) id: string,
|
|
@Body() dto: UpdateSnippetDto,
|
|
) {
|
|
return this.snippetService.update(id, dto);
|
|
}
|
|
|
|
@Delete(":id")
|
|
@HttpCode(204)
|
|
@ApiOperation({ summary: "Delete a snippet" })
|
|
@ApiResponse({ status: 204, description: "Snippet deleted" })
|
|
@ApiResponse({ status: 404, description: "Snippet not found" })
|
|
remove(@Param("id", ParseUUIDPipe) id: string) {
|
|
return this.snippetService.remove(id);
|
|
}
|
|
}
|