feat(#205): renommer absences_garde → evenements_agenda

Migration live + BDD.sql from-scratch, module Nest / API
/evenements-agenda, FK cartes id_evenement. Front stub path aligné.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-01 17:07:54 +02:00
co-authored by Cursor
parent 0842f66df8
commit 2114748d44
25 changed files with 353 additions and 247 deletions
+2 -2
View File
@@ -16,7 +16,7 @@ import { AllExceptionsFilter } from './common/filters/all_exceptions.filters';
import { EnfantsModule } from './routes/enfants/enfants.module';
import { AppConfigModule } from './modules/config/config.module';
import { DocumentsLegauxModule } from './modules/documents-legaux';
import { AbsencesGardeModule } from './modules/absences-garde';
import { EvenementsAgendaModule } from './modules/evenements-agenda';
import { CardsModule } from './modules/cards';
import { RelaisModule } from './routes/relais/relais.module';
import { DossiersModule } from './routes/dossiers/dossiers.module';
@@ -58,7 +58,7 @@ import { SuppressionsModule } from './routes/suppressions/suppressions.module';
AuthModule,
AppConfigModule,
DocumentsLegauxModule,
AbsencesGardeModule,
EvenementsAgendaModule,
CardsModule,
RelaisModule,
DossiersModule,
@@ -9,7 +9,7 @@ import {
UpdateDateColumn,
} from 'typeorm';
import { AmChildren } from './am_children.entity';
import { AbsencesGarde } from './absences_garde.entity';
import { EvenementsAgenda } from './evenements_agenda.entity';
import { Users } from './users.entity';
import { CardType } from './card_types.entity';
import { CardAudienceMember } from './card_audience_members.entity';
@@ -45,12 +45,12 @@ export class CardInstance {
@JoinColumn({ name: 'id_placement', referencedColumnName: 'id' })
placement: AmChildren;
@Column({ name: 'id_absence', type: 'uuid', nullable: true })
id_absence?: string;
@Column({ name: 'id_evenement', type: 'uuid', nullable: true })
id_evenement?: string;
@ManyToOne(() => AbsencesGarde, { nullable: true, onDelete: 'SET NULL' })
@JoinColumn({ name: 'id_absence', referencedColumnName: 'id' })
absence?: AbsencesGarde;
@ManyToOne(() => EvenementsAgenda, { nullable: true, onDelete: 'SET NULL' })
@JoinColumn({ name: 'id_evenement', referencedColumnName: 'id' })
evenement?: EvenementsAgenda;
@Column({ name: 'cree_par', type: 'uuid', nullable: true })
cree_par?: string;
@@ -10,25 +10,25 @@ import {
import { AmChildren } from './am_children.entity';
import { Users } from './users.entity';
export enum TypeAbsenceGardeType {
export enum TypeEvenementAgendaType {
ABSENCE_ENFANT = 'absence_enfant',
CONGE_AM = 'conge_am',
ARRET_MALADIE_AM = 'arret_maladie_am',
}
export enum StatutAbsenceGardeType {
export enum StatutEvenementAgendaType {
EN_ATTENTE = 'en_attente',
ACCEPTE = 'accepte',
REFUSE = 'refuse',
}
/**
* Vérité métier des absences / congés / arrêts par couple AM↔enfant.
* Les cartes (module ultérieur) collectent ; cette table stocke.
* Ticket #193.
* Vérité métier agenda par couple AM↔enfant (placement).
* Types V1 : absences / congés / arrêts ; extensible (soins, école, mairie…).
* Les cartes collectent ; cette table historise. Ticket #205.
*/
@Entity('absences_garde', { schema: 'public' })
export class AbsencesGarde {
@Entity('evenements_agenda', { schema: 'public' })
export class EvenementsAgenda {
@PrimaryGeneratedColumn('uuid')
id: string;
@@ -41,11 +41,11 @@ export class AbsencesGarde {
@Column({
type: 'enum',
enum: TypeAbsenceGardeType,
enumName: 'type_absence_garde_type',
enum: TypeEvenementAgendaType,
enumName: 'type_evenement_agenda_type',
name: 'type',
})
type: TypeAbsenceGardeType;
type: TypeEvenementAgendaType;
@Column({ name: 'date_debut', type: 'date' })
date_debut: string;
@@ -55,12 +55,12 @@ export class AbsencesGarde {
@Column({
type: 'enum',
enum: StatutAbsenceGardeType,
enumName: 'statut_absence_garde_type',
enum: StatutEvenementAgendaType,
enumName: 'statut_evenement_agenda_type',
name: 'statut',
default: StatutAbsenceGardeType.EN_ATTENTE,
default: StatutEvenementAgendaType.EN_ATTENTE,
})
statut: StatutAbsenceGardeType;
statut: StatutEvenementAgendaType;
/** Purge auto pour en_attente/refuse ; accepte → infinity. */
@Column({ name: 'expire_at', type: 'timestamptz' })
@@ -1,2 +0,0 @@
export { AbsencesGardeModule } from './absences-garde.module';
export { AbsencesGardeService } from './absences-garde.service';
@@ -65,7 +65,7 @@ export class CardsController {
@Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE)
@HttpCode(HttpStatus.CREATED)
@ApiOperation({
summary: 'Créer une bulle (+ hook absences_garde) — #194',
summary: 'Créer une bulle (+ hook evenements_agenda) — #194',
})
@ApiBody({ type: CreerCarteDto })
@ApiResponse({ status: 201, type: CarteDto })
+2 -2
View File
@@ -2,7 +2,7 @@ import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { JwtModule } from '@nestjs/jwt';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AbsencesGardeModule } from '../absences-garde';
import { EvenementsAgendaModule } from '../evenements-agenda';
import { CardType } from 'src/entities/card_types.entity';
import { CardInstance } from 'src/entities/card_instances.entity';
import { CardAudienceMember } from 'src/entities/card_audience_members.entity';
@@ -16,7 +16,7 @@ import { CardsRealtimeService } from './cards-realtime.service';
@Module({
imports: [
AbsencesGardeModule,
EvenementsAgendaModule,
TypeOrmModule.forFeature([
CardType,
CardInstance,
@@ -3,7 +3,7 @@ import { getRepositoryToken } from '@nestjs/typeorm';
import { ForbiddenException } from '@nestjs/common';
import { CardsService } from './cards.service';
import { CardsRealtimeService } from './cards-realtime.service';
import { AbsencesGardeService } from '../absences-garde/absences-garde.service';
import { EvenementsAgendaService } from '../evenements-agenda/evenements-agenda.service';
import { CardType, CardResponseModeType } from 'src/entities/card_types.entity';
import {
CardInstance,
@@ -15,7 +15,7 @@ import { CardResponse } from 'src/entities/card_responses.entity';
import { AmChildren } from 'src/entities/am_children.entity';
import { ParentsChildren } from 'src/entities/parents_children.entity';
import { RoleType } from 'src/entities/users.entity';
import { StatutAbsenceGardeType, TypeAbsenceGardeType } from 'src/entities/absences_garde.entity';
import { StatutEvenementAgendaType, TypeEvenementAgendaType } from 'src/entities/evenements_agenda.entity';
describe('CardsService (#194)', () => {
let service: CardsService;
@@ -41,7 +41,7 @@ describe('CardsService (#194)', () => {
};
const amChildrenRepo = { findOne: jest.fn() };
const parentsChildrenRepo = { find: jest.fn(), findOne: jest.fn() };
const absencesService = {
const evenementsService = {
creer: jest.fn(),
maj: jest.fn(),
supprimer: jest.fn(),
@@ -58,7 +58,7 @@ describe('CardsService (#194)', () => {
{ provide: getRepositoryToken(CardResponse), useValue: responsesRepo },
{ provide: getRepositoryToken(AmChildren), useValue: amChildrenRepo },
{ provide: getRepositoryToken(ParentsChildren), useValue: parentsChildrenRepo },
{ provide: AbsencesGardeService, useValue: absencesService },
{ provide: EvenementsAgendaService, useValue: evenementsService },
{ provide: CardsRealtimeService, useValue: realtime },
],
}).compile();
@@ -88,10 +88,10 @@ describe('CardsService (#194)', () => {
enfantId: 'e-1',
date_fin: null,
});
absencesService.creer.mockResolvedValue({
evenementsService.creer.mockResolvedValue({
id: 'abs-1',
type: TypeAbsenceGardeType.CONGE_AM,
statut: StatutAbsenceGardeType.EN_ATTENTE,
type: TypeEvenementAgendaType.CONGE_AM,
statut: StatutEvenementAgendaType.EN_ATTENTE,
});
parentsChildrenRepo.find.mockResolvedValue([
{ parentId: 'p-1', enfantId: 'e-1' },
@@ -101,7 +101,7 @@ describe('CardsService (#194)', () => {
id: 'card-1',
type_code: 'conge_am',
id_placement: 'pl-1',
id_absence: 'abs-1',
id_evenement: 'abs-1',
cree_par: 'am-1',
operation: CardOperationType.CREATE,
statut: CardInstanceStatutType.OUVERTE,
@@ -130,7 +130,7 @@ describe('CardsService (#194)', () => {
date_fin: '2026-11-07',
});
expect(absencesService.creer).toHaveBeenCalled();
expect(evenementsService.creer).toHaveBeenCalled();
expect(audienceRepo.save).toHaveBeenCalled();
expect(realtime.emitToUsers).toHaveBeenCalledWith(
['am-1', 'p-1', 'p-2'],
+28 -28
View File
@@ -6,11 +6,11 @@ import {
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { IsNull, Repository } from 'typeorm';
import { AbsencesGardeService } from '../absences-garde/absences-garde.service';
import { EvenementsAgendaService } from '../evenements-agenda/evenements-agenda.service';
import {
StatutAbsenceGardeType,
TypeAbsenceGardeType,
} from 'src/entities/absences_garde.entity';
StatutEvenementAgendaType,
TypeEvenementAgendaType,
} from 'src/entities/evenements_agenda.entity';
import { AmChildren } from 'src/entities/am_children.entity';
import { ParentsChildren } from 'src/entities/parents_children.entity';
import { RoleType } from 'src/entities/users.entity';
@@ -49,7 +49,7 @@ export class CardsService {
private readonly amChildrenRepo: Repository<AmChildren>,
@InjectRepository(ParentsChildren)
private readonly parentsChildrenRepo: Repository<ParentsChildren>,
private readonly absencesService: AbsencesGardeService,
private readonly evenementsService: EvenementsAgendaService,
private readonly realtime: CardsRealtimeService,
) {}
@@ -110,11 +110,11 @@ export class CardsService {
);
const operation = dto.operation ?? CardOperationType.CREATE;
let absenceId = dto.id_absence;
let absenceId = dto.id_evenement;
const absenceType = this.mapAbsenceType(dto.type_code);
if (operation === CardOperationType.CREATE) {
const absence = await this.absencesService.creer(userId, role, {
const absence = await this.evenementsService.creer(userId, role, {
id_placement: dto.id_placement,
type: absenceType,
date_debut: dto.date_debut,
@@ -124,16 +124,16 @@ export class CardsService {
absenceId = absence.id;
} else {
if (!absenceId) {
throw new BadRequestException('id_absence requis pour operation=update');
throw new BadRequestException('id_evenement requis pour operation=update');
}
await this.absencesService.maj(userId, role, absenceId, {
await this.evenementsService.maj(userId, role, absenceId, {
date_debut: dto.date_debut,
date_fin: dto.date_fin,
motif: dto.motif,
// Congé accepté modifié → repasse en attente via cartes respond flow;
// pour absence enfant update immédiat déjà fait.
...(dto.type_code === 'conge_am'
? { statut: StatutAbsenceGardeType.EN_ATTENTE }
? { statut: StatutEvenementAgendaType.EN_ATTENTE }
: {}),
});
}
@@ -146,7 +146,7 @@ export class CardsService {
const card = this.cardsRepo.create({
type_code: type.code,
id_placement: dto.id_placement,
id_absence: absenceId,
id_evenement: absenceId,
cree_par: userId,
operation,
statut: statutInitial,
@@ -211,15 +211,15 @@ export class CardsService {
comment: dto.comment?.trim() || undefined,
});
if (card.id_absence) {
if (card.id_evenement) {
if (dto.action === CardResponseActionType.ACCEPT || dto.action === CardResponseActionType.ACK) {
await this.absencesService.maj(userId, role, card.id_absence, {
statut: StatutAbsenceGardeType.ACCEPTE,
await this.evenementsService.maj(userId, role, card.id_evenement, {
statut: StatutEvenementAgendaType.ACCEPTE,
});
card.statut = CardInstanceStatutType.TRAITEE;
} else if (dto.action === CardResponseActionType.REFUSE) {
await this.absencesService.maj(userId, role, card.id_absence, {
statut: StatutAbsenceGardeType.REFUSE,
await this.evenementsService.maj(userId, role, card.id_evenement, {
statut: StatutEvenementAgendaType.REFUSE,
motif: dto.comment!.trim(),
});
card.statut = CardInstanceStatutType.REFUSEE;
@@ -264,12 +264,12 @@ export class CardsService {
throw new BadRequestException('Dates invalides');
}
if (card.id_absence) {
await this.absencesService.maj(userId, role, card.id_absence, {
if (card.id_evenement) {
await this.evenementsService.maj(userId, role, card.id_evenement, {
date_debut: debut,
date_fin: fin,
motif: dto.motif,
statut: StatutAbsenceGardeType.EN_ATTENTE,
statut: StatutEvenementAgendaType.EN_ATTENTE,
});
}
@@ -298,17 +298,17 @@ export class CardsService {
throw new ForbiddenException('Seul le créateur peut supprimer cette carte');
}
const audienceIds = await this.audienceUserIds(card);
if (card.id_absence) {
if (card.id_evenement) {
const absStatut =
card.statut === CardInstanceStatutType.TRAITEE
? null
: card.id_absence;
: card.id_evenement;
// Supprime l’absence liée si pas encore acceptée définitivement
if (
card.statut === CardInstanceStatutType.OUVERTE ||
card.statut === CardInstanceStatutType.REFUSEE
) {
await this.absencesService.supprimer(userId, role, card.id_absence);
await this.evenementsService.supprimer(userId, role, card.id_evenement);
}
void absStatut;
}
@@ -336,13 +336,13 @@ export class CardsService {
return rows.map((r) => r.id_utilisateur);
}
private mapAbsenceType(typeCode: string): TypeAbsenceGardeType {
private mapAbsenceType(typeCode: string): TypeEvenementAgendaType {
if (typeCode === 'absence_enfant' || typeCode === 'absence_enfant_modif') {
return TypeAbsenceGardeType.ABSENCE_ENFANT;
return TypeEvenementAgendaType.ABSENCE_ENFANT;
}
if (typeCode === 'conge_am') return TypeAbsenceGardeType.CONGE_AM;
if (typeCode === 'conge_am') return TypeEvenementAgendaType.CONGE_AM;
if (typeCode === 'arret_maladie_am') {
return TypeAbsenceGardeType.ARRET_MALADIE_AM;
return TypeEvenementAgendaType.ARRET_MALADIE_AM;
}
throw new BadRequestException(`Type non mappé à une absence: ${typeCode}`);
}
@@ -350,7 +350,7 @@ export class CardsService {
private async linkAbsenceCard(absenceId: string, cardId: string): Promise<void> {
// Update direct pour éviter droits maj vides
await this.cardsRepo.manager.query(
`UPDATE absences_garde SET id_card_instance = $1, modifie_le = now() WHERE id = $2`,
`UPDATE evenements_agenda SET id_card_instance = $1, modifie_le = now() WHERE id = $2`,
[cardId, absenceId],
);
}
@@ -471,7 +471,7 @@ export class CardsService {
titre: card.type?.titre ?? card.type_code,
couleur: card.type?.couleur ?? null,
id_placement: card.id_placement,
id_absence: card.id_absence ?? null,
id_evenement: card.id_evenement ?? null,
operation: card.operation,
statut: card.statut,
payload: card.payload ?? {},
+3 -3
View File
@@ -38,11 +38,11 @@ export class CreerCarteDto {
motif?: string;
@ApiPropertyOptional({
description: 'Requis pour operation=update (même id absences_garde)',
description: 'Requis pour operation=update (même id evenements_agenda)',
})
@IsOptional()
@IsUUID()
id_absence?: string;
id_evenement?: string;
@ApiPropertyOptional({ enum: CardOperationType, default: CardOperationType.CREATE })
@IsOptional()
@@ -98,7 +98,7 @@ export class CarteDto {
id_placement: string;
@ApiPropertyOptional()
id_absence?: string | null;
id_evenement?: string | null;
@ApiProperty({ enum: CardOperationType })
operation: CardOperationType;
@@ -9,18 +9,18 @@ import {
MinLength,
} from 'class-validator';
import {
StatutAbsenceGardeType,
TypeAbsenceGardeType,
} from 'src/entities/absences_garde.entity';
StatutEvenementAgendaType,
TypeEvenementAgendaType,
} from 'src/entities/evenements_agenda.entity';
export class CreerAbsenceGardeDto {
export class CreerEvenementAgendaDto {
@ApiProperty({ description: 'Placement AM↔enfant (couple)' })
@IsUUID()
id_placement: string;
@ApiProperty({ enum: TypeAbsenceGardeType })
@IsEnum(TypeAbsenceGardeType)
type: TypeAbsenceGardeType;
@ApiProperty({ enum: TypeEvenementAgendaType })
@IsEnum(TypeEvenementAgendaType)
type: TypeEvenementAgendaType;
@ApiProperty({ example: '2026-10-01' })
@IsDateString()
@@ -37,7 +37,7 @@ export class CreerAbsenceGardeDto {
motif?: string;
}
export class MajAbsenceGardeDto {
export class MajEvenementAgendaDto {
@ApiPropertyOptional({ example: '2026-10-02' })
@IsOptional()
@IsDateString()
@@ -48,10 +48,10 @@ export class MajAbsenceGardeDto {
@IsDateString()
date_fin?: string;
@ApiPropertyOptional({ enum: StatutAbsenceGardeType })
@ApiPropertyOptional({ enum: StatutEvenementAgendaType })
@IsOptional()
@IsEnum(StatutAbsenceGardeType)
statut?: StatutAbsenceGardeType;
@IsEnum(StatutEvenementAgendaType)
statut?: StatutEvenementAgendaType;
@ApiPropertyOptional({
description: 'Motivation de refus (parent) ou motif créateur',
@@ -63,15 +63,15 @@ export class MajAbsenceGardeDto {
motif?: string;
}
export class AbsenceGardeDto {
export class EvenementAgendaDto {
@ApiProperty()
id: string;
@ApiProperty()
id_placement: string;
@ApiProperty({ enum: TypeAbsenceGardeType })
type: TypeAbsenceGardeType;
@ApiProperty({ enum: TypeEvenementAgendaType })
type: TypeEvenementAgendaType;
@ApiProperty()
date_debut: string;
@@ -79,8 +79,8 @@ export class AbsenceGardeDto {
@ApiProperty()
date_fin: string;
@ApiProperty({ enum: StatutAbsenceGardeType })
statut: StatutAbsenceGardeType;
@ApiProperty({ enum: StatutEvenementAgendaType })
statut: StatutEvenementAgendaType;
@ApiProperty()
expire_at: string;
@@ -113,7 +113,7 @@ export class AbsenceGardeDto {
modifie_le: string;
}
export class ListeAbsencesGardeDto {
@ApiProperty({ type: [AbsenceGardeDto] })
items: AbsenceGardeDto[];
export class ListeEvenementsAgendaDto {
@ApiProperty({ type: [EvenementAgendaDto] })
items: EvenementAgendaDto[];
}
@@ -1,13 +1,13 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AbsencesGardeController } from './absences-garde.controller';
import { AbsencesGardeService } from './absences-garde.service';
import { EvenementsAgendaController } from './evenements-agenda.controller';
import { EvenementsAgendaService } from './evenements-agenda.service';
import { AuthGuard } from 'src/common/guards/auth.guard';
import { RolesGuard } from 'src/common/guards/roles.guard';
import { RoleType } from 'src/entities/users.entity';
import { TypeAbsenceGardeType } from 'src/entities/absences_garde.entity';
import { TypeEvenementAgendaType } from 'src/entities/evenements_agenda.entity';
describe('AbsencesGardeController (#172)', () => {
let controller: AbsencesGardeController;
describe('EvenementsAgendaController (#172)', () => {
let controller: EvenementsAgendaController;
const serviceMock = {
lister: jest.fn(),
creer: jest.fn(),
@@ -17,8 +17,8 @@ describe('AbsencesGardeController (#172)', () => {
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AbsencesGardeController],
providers: [{ provide: AbsencesGardeService, useValue: serviceMock }],
controllers: [EvenementsAgendaController],
providers: [{ provide: EvenementsAgendaService, useValue: serviceMock }],
})
.overrideGuard(AuthGuard)
.useValue({ canActivate: () => true })
@@ -26,7 +26,7 @@ describe('AbsencesGardeController (#172)', () => {
.useValue({ canActivate: () => true })
.compile();
controller = module.get(AbsencesGardeController);
controller = module.get(EvenementsAgendaController);
jest.clearAllMocks();
});
@@ -59,7 +59,7 @@ describe('AbsencesGardeController (#172)', () => {
serviceMock.creer.mockResolvedValue({ id: 'a1' });
const dto = {
id_placement: 'pl-1',
type: TypeAbsenceGardeType.ABSENCE_ENFANT,
type: TypeEvenementAgendaType.ABSENCE_ENFANT,
date_debut: '2026-10-01',
date_fin: '2026-10-02',
};
@@ -25,49 +25,49 @@ 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';
StatutEvenementAgendaType,
TypeEvenementAgendaType,
} from 'src/entities/evenements_agenda.entity';
import { RoleType } from 'src/entities/users.entity';
import { AbsencesGardeService } from './absences-garde.service';
import { EvenementsAgendaService } from './evenements-agenda.service';
import {
AbsenceGardeDto,
CreerAbsenceGardeDto,
ListeAbsencesGardeDto,
MajAbsenceGardeDto,
} from './dto/absences-garde.dto';
EvenementAgendaDto,
CreerEvenementAgendaDto,
ListeEvenementsAgendaDto,
MajEvenementAgendaDto,
} from './dto/evenements-agenda.dto';
@ApiTags('Absences garde')
@ApiTags('Événements agenda')
@ApiBearerAuth('access-token')
@Controller('absences-garde')
@Controller('evenements-agenda')
@UseGuards(AuthGuard, RolesGuard)
export class AbsencesGardeController {
constructor(private readonly absencesGardeService: AbsencesGardeService) {}
export class EvenementsAgendaController {
constructor(private readonly evenementsAgendaService: EvenementsAgendaService) {}
@Get()
@Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE)
@ApiOperation({
summary: 'Lister les absences / congés / arrêts — ticket #172',
summary: 'Lister les absences / congés / arrêts — ticket #205 / ex-#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: 'type', required: false, enum: TypeEvenementAgendaType })
@ApiQuery({ name: 'statut', required: false, enum: StatutEvenementAgendaType })
@ApiQuery({ name: 'from', required: false, description: 'YYYY-MM-DD' })
@ApiQuery({ name: 'to', required: false, description: 'YYYY-MM-DD' })
@ApiResponse({ status: 200, type: ListeAbsencesGardeDto })
@ApiResponse({ status: 200, type: ListeEvenementsAgendaDto })
lister(
@User('id') userId: string,
@User('role') role: RoleType,
@Query('placementId') placementId?: string,
@Query('type') type?: TypeAbsenceGardeType,
@Query('statut') statut?: StatutAbsenceGardeType,
@Query('type') type?: TypeEvenementAgendaType,
@Query('statut') statut?: StatutEvenementAgendaType,
@Query('from') from?: string,
@Query('to') to?: string,
): Promise<ListeAbsencesGardeDto> {
return this.absencesGardeService.lister(userId, role, {
): Promise<ListeEvenementsAgendaDto> {
return this.evenementsAgendaService.lister(userId, role, {
placementId,
type,
statut,
@@ -79,15 +79,15 @@ export class AbsencesGardeController {
@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 })
@ApiBody({ type: CreerEvenementAgendaDto })
@ApiResponse({ status: 201, type: EvenementAgendaDto })
@HttpCode(HttpStatus.CREATED)
creer(
@User('id') userId: string,
@User('role') role: RoleType,
@Body() dto: CreerAbsenceGardeDto,
): Promise<AbsenceGardeDto> {
return this.absencesGardeService.creer(userId, role, dto);
@Body() dto: CreerEvenementAgendaDto,
): Promise<EvenementAgendaDto> {
return this.evenementsAgendaService.creer(userId, role, dto);
}
@Patch(':id')
@@ -98,15 +98,15 @@ export class AbsencesGardeController {
'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 })
@ApiBody({ type: MajEvenementAgendaDto })
@ApiResponse({ status: 200, type: EvenementAgendaDto })
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);
@Body() dto: MajEvenementAgendaDto,
): Promise<EvenementAgendaDto> {
return this.evenementsAgendaService.maj(userId, role, id, dto);
}
@Delete(':id')
@@ -119,6 +119,6 @@ export class AbsencesGardeController {
@User('role') role: RoleType,
@Param('id', ParseUUIDPipe) id: string,
): Promise<void> {
await this.absencesGardeService.supprimer(userId, role, id);
await this.evenementsAgendaService.supprimer(userId, role, id);
}
}
@@ -2,15 +2,15 @@ import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { JwtModule } from '@nestjs/jwt';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AbsencesGarde } from 'src/entities/absences_garde.entity';
import { EvenementsAgenda } from 'src/entities/evenements_agenda.entity';
import { AmChildren } from 'src/entities/am_children.entity';
import { ParentsChildren } from 'src/entities/parents_children.entity';
import { AbsencesGardeController } from './absences-garde.controller';
import { AbsencesGardeService } from './absences-garde.service';
import { EvenementsAgendaController } from './evenements-agenda.controller';
import { EvenementsAgendaService } from './evenements-agenda.service';
@Module({
imports: [
TypeOrmModule.forFeature([AbsencesGarde, AmChildren, ParentsChildren]),
TypeOrmModule.forFeature([EvenementsAgenda, AmChildren, ParentsChildren]),
JwtModule.registerAsync({
imports: [ConfigModule],
useFactory: (config: ConfigService) => ({
@@ -20,8 +20,8 @@ import { AbsencesGardeService } from './absences-garde.service';
inject: [ConfigService],
}),
],
controllers: [AbsencesGardeController],
providers: [AbsencesGardeService],
exports: [AbsencesGardeService],
controllers: [EvenementsAgendaController],
providers: [EvenementsAgendaService],
exports: [EvenementsAgendaService],
})
export class AbsencesGardeModule {}
export class EvenementsAgendaModule {}
@@ -1,18 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { ForbiddenException, BadRequestException } from '@nestjs/common';
import { AbsencesGardeService } from './absences-garde.service';
import { EvenementsAgendaService } from './evenements-agenda.service';
import {
AbsencesGarde,
StatutAbsenceGardeType,
TypeAbsenceGardeType,
} from 'src/entities/absences_garde.entity';
EvenementsAgenda,
StatutEvenementAgendaType,
TypeEvenementAgendaType,
} from 'src/entities/evenements_agenda.entity';
import { AmChildren } from 'src/entities/am_children.entity';
import { ParentsChildren } from 'src/entities/parents_children.entity';
import { RoleType } from 'src/entities/users.entity';
describe('AbsencesGardeService (#172)', () => {
let service: AbsencesGardeService;
describe('EvenementsAgendaService (#172)', () => {
let service: EvenementsAgendaService;
const absencesRepo = {
create: jest.fn((x) => x),
save: jest.fn(async (x) => ({
@@ -37,8 +37,8 @@ describe('AbsencesGardeService (#172)', () => {
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
AbsencesGardeService,
{ provide: getRepositoryToken(AbsencesGarde), useValue: absencesRepo },
EvenementsAgendaService,
{ provide: getRepositoryToken(EvenementsAgenda), useValue: absencesRepo },
{ provide: getRepositoryToken(AmChildren), useValue: amChildrenRepo },
{
provide: getRepositoryToken(ParentsChildren),
@@ -46,7 +46,7 @@ describe('AbsencesGardeService (#172)', () => {
},
],
}).compile();
service = module.get(AbsencesGardeService);
service = module.get(EvenementsAgendaService);
jest.clearAllMocks();
});
@@ -68,10 +68,10 @@ describe('AbsencesGardeService (#172)', () => {
absencesRepo.findOne.mockResolvedValue({
id: 'abs-1',
id_placement: 'pl-1',
type: TypeAbsenceGardeType.ABSENCE_ENFANT,
type: TypeEvenementAgendaType.ABSENCE_ENFANT,
date_debut: '2026-10-01',
date_fin: '2026-10-02',
statut: StatutAbsenceGardeType.ACCEPTE,
statut: StatutEvenementAgendaType.ACCEPTE,
expire_at: new Date('9999-12-31'),
cree_le: new Date(),
modifie_le: new Date(),
@@ -85,15 +85,15 @@ describe('AbsencesGardeService (#172)', () => {
const res = await service.creer('p-1', RoleType.PARENT, {
id_placement: 'pl-1',
type: TypeAbsenceGardeType.ABSENCE_ENFANT,
type: TypeEvenementAgendaType.ABSENCE_ENFANT,
date_debut: '2026-10-01',
date_fin: '2026-10-02',
});
expect(absencesRepo.save).toHaveBeenCalled();
const savedArg = absencesRepo.save.mock.calls[0][0];
expect(savedArg.statut).toBe(StatutAbsenceGardeType.ACCEPTE);
expect(res.type).toBe(TypeAbsenceGardeType.ABSENCE_ENFANT);
expect(savedArg.statut).toBe(StatutEvenementAgendaType.ACCEPTE);
expect(res.type).toBe(TypeEvenementAgendaType.ABSENCE_ENFANT);
});
it('parent ne peut pas créer un congé AM', async () => {
@@ -110,7 +110,7 @@ describe('AbsencesGardeService (#172)', () => {
await expect(
service.creer('p-1', RoleType.PARENT, {
id_placement: 'pl-1',
type: TypeAbsenceGardeType.CONGE_AM,
type: TypeEvenementAgendaType.CONGE_AM,
date_debut: '2026-10-01',
date_fin: '2026-10-05',
}),
@@ -121,10 +121,10 @@ describe('AbsencesGardeService (#172)', () => {
absencesRepo.findOne.mockResolvedValue({
id: 'abs-1',
id_placement: 'pl-1',
type: TypeAbsenceGardeType.CONGE_AM,
type: TypeEvenementAgendaType.CONGE_AM,
date_debut: '2026-10-01',
date_fin: '2026-10-05',
statut: StatutAbsenceGardeType.EN_ATTENTE,
statut: StatutEvenementAgendaType.EN_ATTENTE,
expire_at: new Date(),
});
amChildrenRepo.findOne.mockResolvedValue({
@@ -140,7 +140,7 @@ describe('AbsencesGardeService (#172)', () => {
await expect(
service.maj('p-1', RoleType.PARENT, 'abs-1', {
statut: StatutAbsenceGardeType.REFUSE,
statut: StatutEvenementAgendaType.REFUSE,
}),
).rejects.toBeInstanceOf(BadRequestException);
});
@@ -159,7 +159,7 @@ describe('AbsencesGardeService (#172)', () => {
await expect(
service.creer('p-1', RoleType.PARENT, {
id_placement: 'pl-1',
type: TypeAbsenceGardeType.ABSENCE_ENFANT,
type: TypeEvenementAgendaType.ABSENCE_ENFANT,
date_debut: '2026-10-10',
date_fin: '2026-10-01',
}),
@@ -7,19 +7,19 @@ import {
import { InjectRepository } from '@nestjs/typeorm';
import { In, IsNull, Repository } from 'typeorm';
import {
AbsencesGarde,
StatutAbsenceGardeType,
TypeAbsenceGardeType,
} from 'src/entities/absences_garde.entity';
EvenementsAgenda,
StatutEvenementAgendaType,
TypeEvenementAgendaType,
} from 'src/entities/evenements_agenda.entity';
import { AmChildren } from 'src/entities/am_children.entity';
import { ParentsChildren } from 'src/entities/parents_children.entity';
import { RoleType } from 'src/entities/users.entity';
import {
AbsenceGardeDto,
CreerAbsenceGardeDto,
ListeAbsencesGardeDto,
MajAbsenceGardeDto,
} from './dto/absences-garde.dto';
EvenementAgendaDto,
CreerEvenementAgendaDto,
ListeEvenementsAgendaDto,
MajEvenementAgendaDto,
} from './dto/evenements-agenda.dto';
const TTL_EN_ATTENTE_MS = 15 * 24 * 60 * 60 * 1000;
const TTL_REFUSE_MS = 7 * 24 * 60 * 60 * 1000;
@@ -27,10 +27,10 @@ const TTL_REFUSE_MS = 7 * 24 * 60 * 60 * 1000;
const EXPIRE_ACCEPTE = new Date('9999-12-31T23:59:59.999Z');
@Injectable()
export class AbsencesGardeService {
export class EvenementsAgendaService {
constructor(
@InjectRepository(AbsencesGarde)
private readonly absencesRepo: Repository<AbsencesGarde>,
@InjectRepository(EvenementsAgenda)
private readonly absencesRepo: Repository<EvenementsAgenda>,
@InjectRepository(AmChildren)
private readonly amChildrenRepo: Repository<AmChildren>,
@InjectRepository(ParentsChildren)
@@ -42,12 +42,12 @@ export class AbsencesGardeService {
role: RoleType,
opts: {
placementId?: string;
type?: TypeAbsenceGardeType;
statut?: StatutAbsenceGardeType;
type?: TypeEvenementAgendaType;
statut?: StatutEvenementAgendaType;
from?: string;
to?: string;
},
): Promise<ListeAbsencesGardeDto> {
): Promise<ListeEvenementsAgendaDto> {
const placementIds = await this.resolvePlacementIds(
userId,
role,
@@ -86,8 +86,8 @@ export class AbsencesGardeService {
async creer(
userId: string,
role: RoleType,
dto: CreerAbsenceGardeDto,
): Promise<AbsenceGardeDto> {
dto: CreerEvenementAgendaDto,
): Promise<EvenementAgendaDto> {
this.assertDates(dto.date_debut, dto.date_fin);
await this.assertCanAccessPlacement(userId, role, dto.id_placement);
this.assertCanCreateType(role, dto.type);
@@ -111,8 +111,8 @@ export class AbsencesGardeService {
userId: string,
role: RoleType,
id: string,
dto: MajAbsenceGardeDto,
): Promise<AbsenceGardeDto> {
dto: MajEvenementAgendaDto,
): Promise<EvenementAgendaDto> {
const row = await this.absencesRepo.findOne({ where: { id } });
if (!row) {
throw new NotFoundException('Absence introuvable');
@@ -128,15 +128,15 @@ export class AbsencesGardeService {
this.assertCanEditDates(role, row);
row.date_debut = debut;
row.date_fin = fin;
if (row.statut === StatutAbsenceGardeType.EN_ATTENTE) {
row.expire_at = this.expireAtFor(StatutAbsenceGardeType.EN_ATTENTE);
if (row.statut === StatutEvenementAgendaType.EN_ATTENTE) {
row.expire_at = this.expireAtFor(StatutEvenementAgendaType.EN_ATTENTE);
}
}
if (dto.statut !== undefined && dto.statut !== row.statut) {
this.assertCanChangeStatut(role, row, dto.statut, dto.motif);
if (
dto.statut === StatutAbsenceGardeType.REFUSE &&
dto.statut === StatutEvenementAgendaType.REFUSE &&
(!dto.motif || !dto.motif.trim())
) {
throw new BadRequestException(
@@ -169,7 +169,7 @@ export class AbsencesGardeService {
if (
role === RoleType.PARENT &&
row.type !== TypeAbsenceGardeType.ABSENCE_ENFANT
row.type !== TypeEvenementAgendaType.ABSENCE_ENFANT
) {
throw new ForbiddenException(
'Un parent ne peut supprimer que les absences enfant',
@@ -183,7 +183,7 @@ export class AbsencesGardeService {
id: string,
userId: string,
role: RoleType,
): Promise<AbsenceGardeDto> {
): Promise<EvenementAgendaDto> {
const row = await this.absencesRepo.findOne({
where: { id },
relations: ['placement', 'placement.child', 'placement.am', 'placement.am.user'],
@@ -195,19 +195,19 @@ export class AbsencesGardeService {
return this.toDto(row);
}
private statutInitial(type: TypeAbsenceGardeType): StatutAbsenceGardeType {
if (type === TypeAbsenceGardeType.ABSENCE_ENFANT) {
return StatutAbsenceGardeType.ACCEPTE;
private statutInitial(type: TypeEvenementAgendaType): StatutEvenementAgendaType {
if (type === TypeEvenementAgendaType.ABSENCE_ENFANT) {
return StatutEvenementAgendaType.ACCEPTE;
}
return StatutAbsenceGardeType.EN_ATTENTE;
return StatutEvenementAgendaType.EN_ATTENTE;
}
private expireAtFor(statut: StatutAbsenceGardeType): Date {
private expireAtFor(statut: StatutEvenementAgendaType): Date {
const now = Date.now();
if (statut === StatutAbsenceGardeType.ACCEPTE) {
if (statut === StatutEvenementAgendaType.ACCEPTE) {
return EXPIRE_ACCEPTE;
}
if (statut === StatutAbsenceGardeType.REFUSE) {
if (statut === StatutEvenementAgendaType.REFUSE) {
return new Date(now + TTL_REFUSE_MS);
}
return new Date(now + TTL_EN_ATTENTE_MS);
@@ -221,9 +221,9 @@ export class AbsencesGardeService {
}
}
private assertCanCreateType(role: RoleType, type: TypeAbsenceGardeType): void {
private assertCanCreateType(role: RoleType, type: TypeEvenementAgendaType): void {
if (role === RoleType.PARENT) {
if (type !== TypeAbsenceGardeType.ABSENCE_ENFANT) {
if (type !== TypeEvenementAgendaType.ABSENCE_ENFANT) {
throw new ForbiddenException(
'Un parent ne peut créer que des absences enfant',
);
@@ -232,8 +232,8 @@ export class AbsencesGardeService {
}
if (role === RoleType.ASSISTANTE_MATERNELLE) {
if (
type !== TypeAbsenceGardeType.CONGE_AM &&
type !== TypeAbsenceGardeType.ARRET_MALADIE_AM
type !== TypeEvenementAgendaType.CONGE_AM &&
type !== TypeEvenementAgendaType.ARRET_MALADIE_AM
) {
throw new ForbiddenException(
'Une AM ne peut créer que congé ou arrêt maladie',
@@ -246,10 +246,10 @@ export class AbsencesGardeService {
private assertCanEditDates(
role: RoleType,
row: AbsencesGarde,
row: EvenementsAgenda,
): void {
if (role === RoleType.PARENT) {
if (row.type !== TypeAbsenceGardeType.ABSENCE_ENFANT) {
if (row.type !== TypeEvenementAgendaType.ABSENCE_ENFANT) {
throw new ForbiddenException(
'Un parent ne peut modifier que les absences enfant',
);
@@ -258,13 +258,13 @@ export class AbsencesGardeService {
}
if (role === RoleType.ASSISTANTE_MATERNELLE) {
if (
row.type === TypeAbsenceGardeType.CONGE_AM ||
row.type === TypeAbsenceGardeType.ARRET_MALADIE_AM
row.type === TypeEvenementAgendaType.CONGE_AM ||
row.type === TypeEvenementAgendaType.ARRET_MALADIE_AM
) {
if (
row.statut !== StatutAbsenceGardeType.EN_ATTENTE &&
row.statut !== StatutAbsenceGardeType.REFUSE &&
row.statut !== StatutAbsenceGardeType.ACCEPTE
row.statut !== StatutEvenementAgendaType.EN_ATTENTE &&
row.statut !== StatutEvenementAgendaType.REFUSE &&
row.statut !== StatutEvenementAgendaType.ACCEPTE
) {
throw new ForbiddenException('Statut incompatible avec une modification');
}
@@ -278,31 +278,31 @@ export class AbsencesGardeService {
private assertCanChangeStatut(
role: RoleType,
row: AbsencesGarde,
next: StatutAbsenceGardeType,
row: EvenementsAgenda,
next: StatutEvenementAgendaType,
_motif?: string,
): void {
if (role === RoleType.PARENT) {
// Accept / refuse congé ; ack arrêt (accepte)
if (
row.type === TypeAbsenceGardeType.CONGE_AM ||
row.type === TypeAbsenceGardeType.ARRET_MALADIE_AM
row.type === TypeEvenementAgendaType.CONGE_AM ||
row.type === TypeEvenementAgendaType.ARRET_MALADIE_AM
) {
if (
next !== StatutAbsenceGardeType.ACCEPTE &&
next !== StatutAbsenceGardeType.REFUSE
next !== StatutEvenementAgendaType.ACCEPTE &&
next !== StatutEvenementAgendaType.REFUSE
) {
throw new BadRequestException('Transition de statut invalide');
}
if (
row.type === TypeAbsenceGardeType.ARRET_MALADIE_AM &&
next === StatutAbsenceGardeType.REFUSE
row.type === TypeEvenementAgendaType.ARRET_MALADIE_AM &&
next === StatutEvenementAgendaType.REFUSE
) {
throw new BadRequestException(
'Un arrêt maladie ne se refuse pas (accusé seulement)',
);
}
if (row.statut !== StatutAbsenceGardeType.EN_ATTENTE) {
if (row.statut !== StatutEvenementAgendaType.EN_ATTENTE) {
throw new BadRequestException('Cette demande n’est plus en attente');
}
return;
@@ -314,9 +314,9 @@ export class AbsencesGardeService {
if (role === RoleType.ASSISTANTE_MATERNELLE) {
// Remise en attente après refus OU modification d’un congé déjà accepté (S2b)
if (
next === StatutAbsenceGardeType.EN_ATTENTE &&
(row.statut === StatutAbsenceGardeType.REFUSE ||
row.statut === StatutAbsenceGardeType.ACCEPTE)
next === StatutEvenementAgendaType.EN_ATTENTE &&
(row.statut === StatutEvenementAgendaType.REFUSE ||
row.statut === StatutEvenementAgendaType.ACCEPTE)
) {
return;
}
@@ -396,7 +396,7 @@ export class AbsencesGardeService {
throw new ForbiddenException('Rôle non autorisé');
}
private toDto(row: AbsencesGarde): AbsenceGardeDto {
private toDto(row: EvenementsAgenda): EvenementAgendaDto {
const child = row.placement?.child;
const amUser = row.placement?.am?.user;
return {
@@ -0,0 +1,2 @@
export { EvenementsAgendaModule } from './evenements-agenda.module';
export { EvenementsAgendaService } from './evenements-agenda.service';