65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
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<Parents[]> {
|
|
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<Parents> {
|
|
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<Parents> {
|
|
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<Parents> {
|
|
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<void> {
|
|
return this.parentsService.remove(id);
|
|
}
|
|
}
|