import { Body, Controller, Delete, Get, Param, Patch, Post, } from '@nestjs/common'; import { ParentsService } from './parents.service'; import { Parents } from 'src/entities/parents.entity'; import { Roles } from 'src/common/decorators/roles.decorator'; import { RoleType } from 'src/entities/users.entity'; import { ApiBody, ApiResponse, ApiTags } from '@nestjs/swagger'; import { CreateParentDto } from '../user/dto/create_parent.dto'; import { UpdateParentsDto } from '../user/dto/update_parent.dto'; @ApiTags('Parents') @Controller('parents') export class ParentsController { constructor(private readonly parentsService: ParentsService) {} @Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE) @Get() @ApiResponse({ status: 200, description: 'Liste des parents' }) @ApiResponse({ status: 403, description: 'Accès refusé : Réservé aux super_admins' }) getAll(): Promise { return this.parentsService.findAll(); } @Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE) @Get(':id') @ApiResponse({ status: 200, description: 'Détails du parent par ID utilisateur' }) @ApiResponse({ status: 404, description: 'Parent non trouvé' }) getOne(@Param('id') user_id: string): Promise { return this.parentsService.findOne(user_id); } @Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE) @Post() @ApiBody({ type: CreateParentDto }) @ApiResponse({ status: 201, description: 'Parent créé avec succès' }) create(@Body() dto: CreateParentDto): Promise { return this.parentsService.create(dto); } @Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE) @Patch(':id') @ApiBody({ type: UpdateParentsDto }) @ApiResponse({ status: 200, description: 'Parent mis à jour avec succès' }) @ApiResponse({ status: 404, description: 'Parent introuvable' }) update(@Param('id') id: string, @Body() dto: UpdateParentsDto): Promise { return this.parentsService.update(id, dto); } @Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE) @Delete(':id') @ApiResponse({ status: 200, description: 'Parent supprimé avec succès' }) @ApiResponse({ status: 404, description: 'Parent introuvable' }) @ApiResponse({ status: 403, description: 'Accès refusé' }) remove(@Param('id') id: string): Promise { return this.parentsService.remove(id); } }