import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, ParseUUIDPipe, Patch, Post, Query, UseGuards, } from '@nestjs/common'; import { ApiBearerAuth, ApiBody, ApiOperation, ApiQuery, ApiResponse, ApiTags, } from '@nestjs/swagger'; import { AuthGuard } from 'src/common/guards/auth.guard'; import { RolesGuard } from 'src/common/guards/roles.guard'; import { Roles } from 'src/common/decorators/roles.decorator'; import { User } from 'src/common/decorators/user.decorator'; import { RoleType } from 'src/entities/users.entity'; import { CardsService } from './cards.service'; import { CarteDto, CreerCarteDto, ListeCartesDto, MajCarteDto, RepondreCarteDto, } from './dto/cards.dto'; @ApiTags('Cartes') @ApiBearerAuth('access-token') @Controller('cards') @UseGuards(AuthGuard, RolesGuard) export class CardsController { constructor(private readonly cardsService: CardsService) {} @Get('types') @Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE) @ApiOperation({ summary: 'Types SYSTEM émissibles pour mon rôle — #194' }) listerTypes(@User('role') role: RoleType) { return this.cardsService.listerTypes(role); } @Get() @Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE) @ApiOperation({ summary: 'Feed bulles de l’utilisateur — #194' }) @ApiQuery({ name: 'placementId', required: false }) @ApiResponse({ status: 200, type: ListeCartesDto }) lister( @User('id') userId: string, @User('role') role: RoleType, @Query('placementId') placementId?: string, ): Promise { return this.cardsService.lister(userId, role, placementId); } @Post() @Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE) @HttpCode(HttpStatus.CREATED) @ApiOperation({ summary: 'Créer une bulle (+ hook evenements_agenda) — #194', }) @ApiBody({ type: CreerCarteDto }) @ApiResponse({ status: 201, type: CarteDto }) creer( @User('id') userId: string, @User('role') role: RoleType, @Body() dto: CreerCarteDto, ): Promise { return this.cardsService.creer(userId, role, dto); } @Post(':id/respond') @Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE) @ApiOperation({ summary: 'Répondre (accept / refuse / ack) — #194' }) @ApiBody({ type: RepondreCarteDto }) repondre( @User('id') userId: string, @User('role') role: RoleType, @Param('id', ParseUUIDPipe) id: string, @Body() dto: RepondreCarteDto, ): Promise { return this.cardsService.repondre(userId, role, id, dto); } @Patch(':id') @Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE) @ApiOperation({ summary: 'Modifier dates (créateur, ouverte/refusée) — #194', }) @ApiBody({ type: MajCarteDto }) maj( @User('id') userId: string, @User('role') role: RoleType, @Param('id', ParseUUIDPipe) id: string, @Body() dto: MajCarteDto, ): Promise { return this.cardsService.majEnAttente(userId, role, id, dto); } @Delete(':id') @Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE) @HttpCode(HttpStatus.NO_CONTENT) @ApiOperation({ summary: 'Supprimer bulle (+ absence si non traitée) — #194' }) async supprimer( @User('id') userId: string, @User('role') role: RoleType, @Param('id', ParseUUIDPipe) id: string, ): Promise { await this.cardsService.supprimer(userId, role, id); } }