- add PaginationQueryDto<TOrderBy> generic with orderBy and orderDir fields - add SessionOrderBy, EnvironmentOrderBy, ScenarioOrderBy type aliases - update session, environment, scenario services and controllers to use typed pagination - update MCP list_sessions, list_environments, list_scenarios tools to expose orderBy/orderDir - update tests for all list endpoints to cover page, limit, ordering, and invalid param rejection
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { Controller, Delete, Get, NotFoundException, Param, ParseIntPipe, Query } from '@nestjs/common';
|
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
import { SessionService } from './session.service';
|
|
import { PaginationQueryDto } from '../common/dto/pagination.dto';
|
|
import { SessionOrderBy } from './session.service';
|
|
|
|
@ApiTags('sessions')
|
|
@Controller('sessions')
|
|
export class SessionController {
|
|
constructor(private readonly sessionService: SessionService) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'List all stored sessions (paginated)' })
|
|
@ApiResponse({ status: 200, description: 'Paginated sessions' })
|
|
findAll(@Query() query: PaginationQueryDto<SessionOrderBy>) {
|
|
return this.sessionService.findAll(query);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@ApiOperation({ summary: 'Delete a session by ID' })
|
|
@ApiResponse({ status: 200, description: 'Session deleted' })
|
|
@ApiResponse({ status: 404, description: 'Session not found' })
|
|
async remove(@Param('id', ParseIntPipe) id: number): Promise<void> {
|
|
const sessions = await this.sessionService.findAll();
|
|
if (!sessions.data.find(s => s.id === id)) {
|
|
throw new NotFoundException(`Session ${id} not found`);
|
|
}
|
|
await this.sessionService.remove(id);
|
|
}
|
|
}
|