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

64 lines
1.9 KiB
TypeScript

import {
Controller,
Delete,
Get,
HttpCode,
NotFoundException,
Param,
ParseUUIDPipe,
Query,
} from "@nestjs/common";
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
import { SessionQueryDto } from "./session-query.dto";
import { SessionContextService } from "./session-context.service";
import { SessionService } from "./session.service";
function maskToken(token: string, head = 6, tail = 4): string {
if (token.length <= head + tail + 1) return token;
return `${token.slice(0, head)}\u2026${token.slice(-tail)}`;
}
@ApiTags("sessions")
@Controller("sessions")
export class SessionController {
constructor(
private readonly sessionService: SessionService,
private readonly sessionContextService: SessionContextService,
) {}
@Get()
@ApiOperation({ summary: "List all stored sessions (paginated)" })
@ApiResponse({ status: 200, description: "Paginated sessions" })
findAll(@Query() query: SessionQueryDto) {
return this.sessionService.findAll(query);
}
@Get(":id")
@ApiOperation({ summary: "Get a session by ID" })
@ApiResponse({ status: 200, description: "Session found" })
@ApiResponse({ status: 404, description: "Session not found" })
async findOne(@Param("id", ParseUUIDPipe) id: string) {
const session = await this.sessionService.findById(id);
if (!session) throw new NotFoundException(`Session ${id} not found`);
const {
token,
cookies: _cookies,
localStorage: _localStorage,
...rest
} = session;
return {
...rest,
token: maskToken(token),
};
}
@Delete(":id")
@HttpCode(204)
@ApiOperation({ summary: "Delete a session by ID (closes it first if open)" })
@ApiResponse({ status: 204, description: "Session deleted" })
@ApiResponse({ status: 404, description: "Session not found" })
async remove(@Param("id", ParseUUIDPipe) id: string): Promise<void> {
await this.sessionContextService.delete(id);
}
}