feat(#172): API absences-garde (liste, CRUD, droits parent/AM)
Closes #172 Co-authored-by: Julien Martin <julien.martin@ptits-pas.fr>
This commit was merged in pull request #201.
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
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 {
|
||||
StatutAbsenceGardeType,
|
||||
TypeAbsenceGardeType,
|
||||
} from 'src/entities/absences_garde.entity';
|
||||
import { RoleType } from 'src/entities/users.entity';
|
||||
import { AbsencesGardeService } from './absences-garde.service';
|
||||
import {
|
||||
AbsenceGardeDto,
|
||||
CreerAbsenceGardeDto,
|
||||
ListeAbsencesGardeDto,
|
||||
MajAbsenceGardeDto,
|
||||
} from './dto/absences-garde.dto';
|
||||
|
||||
@ApiTags('Absences garde')
|
||||
@ApiBearerAuth('access-token')
|
||||
@Controller('absences-garde')
|
||||
@UseGuards(AuthGuard, RolesGuard)
|
||||
export class AbsencesGardeController {
|
||||
constructor(private readonly absencesGardeService: AbsencesGardeService) {}
|
||||
|
||||
@Get()
|
||||
@Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE)
|
||||
@ApiOperation({
|
||||
summary: 'Lister les absences / congés / arrêts — ticket #172',
|
||||
description:
|
||||
'Sans placementId : tous les placements du user (parent = famille multi-AM ; AM = tous accueils). ' +
|
||||
'Avec placementId : un couple enfant–AM.',
|
||||
})
|
||||
@ApiQuery({ name: 'placementId', required: false })
|
||||
@ApiQuery({ name: 'type', required: false, enum: TypeAbsenceGardeType })
|
||||
@ApiQuery({ name: 'statut', required: false, enum: StatutAbsenceGardeType })
|
||||
@ApiQuery({ name: 'from', required: false, description: 'YYYY-MM-DD' })
|
||||
@ApiQuery({ name: 'to', required: false, description: 'YYYY-MM-DD' })
|
||||
@ApiResponse({ status: 200, type: ListeAbsencesGardeDto })
|
||||
lister(
|
||||
@User('id') userId: string,
|
||||
@User('role') role: RoleType,
|
||||
@Query('placementId') placementId?: string,
|
||||
@Query('type') type?: TypeAbsenceGardeType,
|
||||
@Query('statut') statut?: StatutAbsenceGardeType,
|
||||
@Query('from') from?: string,
|
||||
@Query('to') to?: string,
|
||||
): Promise<ListeAbsencesGardeDto> {
|
||||
return this.absencesGardeService.lister(userId, role, {
|
||||
placementId,
|
||||
type,
|
||||
statut,
|
||||
from,
|
||||
to,
|
||||
});
|
||||
}
|
||||
|
||||
@Post()
|
||||
@Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE)
|
||||
@ApiOperation({ summary: 'Créer une période d’absence / congé / arrêt — #172' })
|
||||
@ApiBody({ type: CreerAbsenceGardeDto })
|
||||
@ApiResponse({ status: 201, type: AbsenceGardeDto })
|
||||
@HttpCode(HttpStatus.CREATED)
|
||||
creer(
|
||||
@User('id') userId: string,
|
||||
@User('role') role: RoleType,
|
||||
@Body() dto: CreerAbsenceGardeDto,
|
||||
): Promise<AbsenceGardeDto> {
|
||||
return this.absencesGardeService.creer(userId, role, dto);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
@Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE)
|
||||
@ApiOperation({
|
||||
summary: 'Mettre à jour dates / statut / motif — #172',
|
||||
description:
|
||||
'Parent : accept/refuse congé (motivation si refus), ack arrêt. ' +
|
||||
'AM : modifier dates (en attente / refuse / accepté), republication après refus.',
|
||||
})
|
||||
@ApiBody({ type: MajAbsenceGardeDto })
|
||||
@ApiResponse({ status: 200, type: AbsenceGardeDto })
|
||||
maj(
|
||||
@User('id') userId: string,
|
||||
@User('role') role: RoleType,
|
||||
@Param('id', ParseUUIDPipe) id: string,
|
||||
@Body() dto: MajAbsenceGardeDto,
|
||||
): Promise<AbsenceGardeDto> {
|
||||
return this.absencesGardeService.maj(userId, role, id, dto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE)
|
||||
@HttpCode(HttpStatus.NO_CONTENT)
|
||||
@ApiOperation({ summary: 'Supprimer une absence (hard delete) — #172' })
|
||||
@ApiResponse({ status: 204 })
|
||||
async supprimer(
|
||||
@User('id') userId: string,
|
||||
@User('role') role: RoleType,
|
||||
@Param('id', ParseUUIDPipe) id: string,
|
||||
): Promise<void> {
|
||||
await this.absencesGardeService.supprimer(userId, role, id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user