- Une entrée par famille (co_parent + enfants partagés, même logique que backfill #103) - libelle, parentIds, numero_dossier ; filtre statut en_attente - AuthGuard + RolesGuard sur controller parents Made-with: Cursor
73 lines
2.9 KiB
TypeScript
73 lines
2.9 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
UseGuards,
|
|
} 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, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
import { CreateParentDto } from '../user/dto/create_parent.dto';
|
|
import { UpdateParentsDto } from '../user/dto/update_parent.dto';
|
|
import { AuthGuard } from 'src/common/guards/auth.guard';
|
|
import { RolesGuard } from 'src/common/guards/roles.guard';
|
|
import { PendingFamilyDto } from './dto/pending-family.dto';
|
|
|
|
@ApiTags('Parents')
|
|
@Controller('parents')
|
|
@UseGuards(AuthGuard, RolesGuard)
|
|
export class ParentsController {
|
|
constructor(private readonly parentsService: ParentsService) {}
|
|
|
|
@Get('pending-families')
|
|
@Roles(RoleType.SUPER_ADMIN, RoleType.ADMINISTRATEUR, RoleType.GESTIONNAIRE)
|
|
@ApiOperation({ summary: 'Liste des familles en attente (une entrée par famille)' })
|
|
@ApiResponse({ status: 200, description: 'Liste des familles (libellé, parentIds, numero_dossier)', type: [PendingFamilyDto] })
|
|
@ApiResponse({ status: 403, description: 'Accès refusé' })
|
|
getPendingFamilies(): Promise<PendingFamilyDto[]> {
|
|
return this.parentsService.getPendingFamilies();
|
|
}
|
|
|
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE, RoleType.ADMINISTRATEUR)
|
|
@Get()
|
|
@ApiResponse({ status: 200, type: [Parents], description: 'Liste des parents' })
|
|
@ApiResponse({ status: 403, description: 'Accès refusé !' })
|
|
getAll(): Promise<Parents[]> {
|
|
return this.parentsService.findAll();
|
|
}
|
|
|
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
|
@Get(':id')
|
|
@ApiResponse({ status: 200, type: Parents, description: 'Détails du parent par ID utilisateur' })
|
|
@ApiResponse({ status: 404, description: 'Parent non trouvé' })
|
|
@ApiResponse({ status: 403, description: 'Accès refusé !' })
|
|
getOne(@Param('id') user_id: string): Promise<Parents> {
|
|
return this.parentsService.findOne(user_id);
|
|
}
|
|
|
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
|
@Post()
|
|
@ApiBody({ type: CreateParentDto })
|
|
@ApiResponse({ status: 201, type: Parents, description: 'Parent créé avec succès' })
|
|
@ApiResponse({ status: 403, description: 'Accès refusé !' })
|
|
create(@Body() dto: CreateParentDto): Promise<Parents> {
|
|
return this.parentsService.create(dto);
|
|
}
|
|
|
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
|
@Patch(':id')
|
|
@ApiBody({ type: UpdateParentsDto })
|
|
@ApiResponse({ status: 200, type: Parents, description: 'Parent mis à jour avec succès' })
|
|
@ApiResponse({ status: 404, description: 'Parent introuvable' })
|
|
@ApiResponse({ status: 403, description: 'Accès refusé !' })
|
|
update(@Param('id') id: string, @Body() dto: UpdateParentsDto): Promise<Parents> {
|
|
return this.parentsService.update(id, dto);
|
|
}
|
|
}
|