feat(sessions): add GET /sessions and DELETE /sessions/:id endpoints

This commit is contained in:
2026-04-07 12:44:08 +03:00
parent 238ce0289c
commit 49dd1aa14c
3 changed files with 52 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
import { Controller, Delete, Get, NotFoundException, Param, ParseIntPipe } from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { SessionService } from './session.service';
@ApiTags('sessions')
@Controller('sessions')
export class SessionController {
constructor(private readonly sessionService: SessionService) {}
@Get()
@ApiOperation({ summary: 'List all stored sessions' })
@ApiResponse({
status: 200,
description: 'Array of sessions',
schema: {
type: 'array',
items: {
properties: {
id: { type: 'number' },
sessionName: { type: 'string' },
createdAt: { type: 'string', format: 'date-time' },
updatedAt: { type: 'string', format: 'date-time' },
},
},
},
})
findAll() {
return this.sessionService.findAll();
}
@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.find(s => s.id === id)) {
throw new NotFoundException(`Session ${id} not found`);
}
await this.sessionService.remove(id);
}
}