Files
liqa/server/src/credential/credential.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

83 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 { CredentialQueryDto } from "./dto/credential-query.dto";
import { CredentialService } from "./credential.service";
import { CreateCredentialDto } from "./dto/create-credential.dto";
import { CredentialExportDto } from "./dto/credential-export.dto";
import { UpdateCredentialDto } from "./dto/update-credential.dto";
@ApiTags("credentials")
@Controller("credentials")
export class CredentialController {
constructor(private readonly credentialService: CredentialService) {}
@Post()
@ApiOperation({ summary: "Create a new credential" })
@ApiResponse({ status: 201, description: "Credential created" })
create(@Body() dto: CreateCredentialDto) {
return this.credentialService.create(dto);
}
@Post("import")
@ApiOperation({ summary: "Import a credential (upsert by id)" })
@ApiResponse({ status: 201, description: "Credential imported" })
async importCredential(@Body() dto: CredentialExportDto) {
return this.credentialService.importCredential(dto);
}
@Get()
@ApiOperation({ summary: "List all credentials (paginated)" })
@ApiResponse({ status: 200, description: "Paginated credentials" })
findAll(@Query() query: CredentialQueryDto) {
return this.credentialService.findAll(query);
}
@Get(":id/export")
@ApiOperation({ summary: "Export a credential as a plain object" })
@ApiResponse({ status: 200, description: "Credential export payload" })
@ApiResponse({ status: 404, description: "Credential not found" })
async exportCredential(@Param("id", ParseUUIDPipe) id: string) {
const credential = await this.credentialService.findOne(id);
return this.credentialService.exportCredential(credential);
}
@Get(":id")
@ApiOperation({ summary: "Get credential by ID" })
@ApiResponse({ status: 200, description: "Credential record" })
@ApiResponse({ status: 404, description: "Credential not found" })
findOne(@Param("id", ParseUUIDPipe) id: string) {
return this.credentialService.findOne(id);
}
@Patch(":id")
@ApiOperation({ summary: "Update a credential" })
@ApiResponse({ status: 200, description: "Credential updated" })
@ApiResponse({ status: 404, description: "Credential not found" })
update(
@Param("id", ParseUUIDPipe) id: string,
@Body() dto: UpdateCredentialDto,
) {
return this.credentialService.update(id, dto);
}
@Delete(":id")
@HttpCode(204)
@ApiOperation({ summary: "Delete a credential" })
@ApiResponse({ status: 204, description: "Credential deleted" })
@ApiResponse({ status: 404, description: "Credential not found" })
remove(@Param("id", ParseUUIDPipe) id: string) {
return this.credentialService.remove(id);
}
}