forked from Ynov/ptitspas-ynov-back
64 lines
2.8 KiB
TypeScript
64 lines
2.8 KiB
TypeScript
import { Body, Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, UseGuards } from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
import { RolesGuard } from 'src/common/guards/roles.guard';
|
|
import { EnfantsService } from './enfants.service';
|
|
import { Roles } from 'src/common/decorators/roles.decorator';
|
|
import { RoleType } from 'src/entities/users.entity';
|
|
import { Children } from 'src/entities/children.entity';
|
|
import { CreateEnfantsDto } from './dto/create_enfants.dto';
|
|
|
|
@ApiBearerAuth()
|
|
@ApiTags('Enfants')
|
|
@UseGuards(RolesGuard)
|
|
@Controller('enfants')
|
|
export class EnfantsController {
|
|
constructor(private readonly enfantsService: EnfantsService) { }
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: 'Inscrire un enfant' })
|
|
@ApiResponse({ status: 201, type: Children, description: 'L\'enfant a été inscrit avec succès.' })
|
|
@Roles(RoleType.PARENT, RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
|
async create(@Body() dto: CreateEnfantsDto): Promise<Children> {
|
|
return this.enfantsService.create(dto);
|
|
}
|
|
|
|
// Récupérer tous les enfants avec leurs liens parents
|
|
@ApiOperation({ summary: 'Récupérer tous les enfants avec leurs liens parents' })
|
|
@ApiResponse({ status: 200, type: [Children], description: 'Liste de tous les enfants avec leurs liens parents.' })
|
|
@Get()
|
|
@Roles(RoleType.GESTIONNAIRE, RoleType.SUPER_ADMIN)
|
|
async findAll(): Promise<Children[]> {
|
|
return this.enfantsService.findAll();
|
|
}
|
|
|
|
// Récupérer un enfant par son ID
|
|
@Get(':id')
|
|
@ApiOperation({ summary: 'Récupérer un enfant par son ID' })
|
|
@ApiResponse({ status: 200, type: Children, description: 'Détails de l\'enfant avec ses liens parents.' })
|
|
@Roles(RoleType.GESTIONNAIRE, RoleType.SUPER_ADMIN, RoleType.PARENT)
|
|
async findOne(@Param('id', new ParseUUIDPipe()) id: string): Promise<Children> {
|
|
return this.enfantsService.findOne(id);
|
|
}
|
|
|
|
// Mettre à jour un enfant
|
|
@Patch(':id')
|
|
@ApiOperation({ summary: 'Mettre à jour un enfant' })
|
|
@ApiResponse({ status: 200, type: Children, description: 'L\'enfant a été mis à jour avec succès.' })
|
|
@Roles(RoleType.GESTIONNAIRE, RoleType.SUPER_ADMIN)
|
|
async update(
|
|
@Param('id', new ParseUUIDPipe()) id: string,
|
|
@Body() dto: Partial<CreateEnfantsDto>,
|
|
): Promise<Children> {
|
|
return this.enfantsService.update(id, dto);
|
|
}
|
|
|
|
// Supprimer un enfant
|
|
@Delete(':id')
|
|
@Roles(RoleType.GESTIONNAIRE, RoleType.SUPER_ADMIN)
|
|
@ApiOperation({ summary: 'Supprimer un enfant' })
|
|
@ApiResponse({ status: 204, description: 'L\'enfant a été supprimé avec succès.' })
|
|
async remove(@Param('id', new ParseUUIDPipe()) id: string): Promise<void> {
|
|
return this.enfantsService.remove(id);
|
|
}
|
|
}
|