mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-08 15:58:18 +00:00
56 lines
2.8 KiB
TypeScript
56 lines
2.8 KiB
TypeScript
import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiResponse, ApiBody } from '@nestjs/swagger';
|
|
import { IsPublic } from '@tria-plc/api-common/modules/auth/decorators/public.decorator';
|
|
import { SeatClassesService } from './seat-classes.service';
|
|
import { CreateSeatClassDto, UpdateSeatClassDto } from './seat-classes.dto';
|
|
import { PassengerDelete, PassengerWrite } from '../../common/passenger-guards';
|
|
import { PASSENGER_PERMS } from '../../seed/passenger-permissions.registry';
|
|
|
|
@ApiTags('Seat Classes')
|
|
@Controller('seat-classes')
|
|
export class SeatClassesController {
|
|
constructor(private service: SeatClassesService) {}
|
|
|
|
@Get()
|
|
@IsPublic()
|
|
@ApiOperation({ summary: 'List all seat classes' })
|
|
@ApiResponse({ status: 200, description: 'Returns all seat classes with their coaches' })
|
|
listSeatClasses() { return this.service.listSeatClasses(); }
|
|
|
|
@Get(':id')
|
|
@IsPublic()
|
|
@ApiOperation({ summary: 'Get a seat class by ID' })
|
|
@ApiParam({ name: 'id', description: 'Seat class UUID' })
|
|
@ApiResponse({ status: 200, description: 'Returns seat class with its coaches' })
|
|
@ApiResponse({ status: 404, description: 'Seat class not found' })
|
|
getSeatClass(@Param('id') id: string) { return this.service.getSeatClass(id); }
|
|
|
|
@Post()
|
|
@PassengerWrite(PASSENGER_PERMS.tariffRates.create, PASSENGER_PERMS.tariffRates.manage) @ApiBearerAuth('IAM-auth')
|
|
@ApiOperation({ summary: 'Create a seat class' })
|
|
@ApiBody({ type: CreateSeatClassDto })
|
|
@ApiResponse({ status: 201, description: 'Seat class created' })
|
|
@ApiResponse({ status: 409, description: 'Seat class name already exists' })
|
|
createSeatClass(@Body() dto: CreateSeatClassDto) { return this.service.createSeatClass(dto); }
|
|
|
|
@Patch(':id')
|
|
@PassengerWrite(PASSENGER_PERMS.tariffRates.edit, PASSENGER_PERMS.tariffRates.manage) @ApiBearerAuth('IAM-auth')
|
|
@ApiOperation({ summary: 'Update a seat class' })
|
|
@ApiParam({ name: 'id', description: 'Seat class UUID' })
|
|
@ApiBody({ type: UpdateSeatClassDto })
|
|
@ApiResponse({ status: 200, description: 'Seat class updated' })
|
|
@ApiResponse({ status: 404, description: 'Seat class not found' })
|
|
updateSeatClass(@Param('id') id: string, @Body() dto: UpdateSeatClassDto) { return this.service.updateSeatClass(id, dto); }
|
|
|
|
@Delete(':id')
|
|
@PassengerDelete(PASSENGER_PERMS.tariffRates.delete)
|
|
@ApiBearerAuth('IAM-auth')
|
|
@ApiOperation({ summary: 'Delete a seat class' })
|
|
@ApiParam({ name: 'id', description: 'Seat class UUID' })
|
|
@ApiResponse({ status: 200, description: 'Seat class deleted' })
|
|
@ApiResponse({ status: 404, description: 'Seat class not found' })
|
|
deleteSeatClass(@Param('id') id: string, @Query('cascade') cascade?: string) {
|
|
return this.service.deleteSeatClass(id, cascade === 'true');
|
|
}
|
|
}
|