feat(#215): Agenda B1 — GET :id + DTO enrichi #231
@@ -12,6 +12,7 @@ import {
|
|||||||
StatutEvenementAgendaType,
|
StatutEvenementAgendaType,
|
||||||
TypeEvenementAgendaType,
|
TypeEvenementAgendaType,
|
||||||
} from 'src/entities/evenements_agenda.entity';
|
} from 'src/entities/evenements_agenda.entity';
|
||||||
|
import { AgendaLotStatutType } from 'src/entities/agenda_lots.entity';
|
||||||
|
|
||||||
export class CreerEvenementAgendaDto {
|
export class CreerEvenementAgendaDto {
|
||||||
@ApiProperty({ description: 'Placement AM↔enfant (couple)' })
|
@ApiProperty({ description: 'Placement AM↔enfant (couple)' })
|
||||||
@@ -63,6 +64,25 @@ export class MajEvenementAgendaDto {
|
|||||||
motif?: string;
|
motif?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Droits calculés pour l’utilisateur courant — #215 */
|
||||||
|
export class EvenementAgendaActionsDto {
|
||||||
|
@ApiProperty({ description: 'Peut modifier dates / resoumettre (créateur)' })
|
||||||
|
peut_modifier: boolean;
|
||||||
|
|
||||||
|
@ApiProperty({ description: 'Peut annuler / soft-cancel (créateur)' })
|
||||||
|
peut_supprimer: boolean;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'Peut accept/refuse (parent habilité, congé en attente)',
|
||||||
|
})
|
||||||
|
peut_accepter_refuser: boolean;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'Peut ack informatif (ex. arrêt maladie)',
|
||||||
|
})
|
||||||
|
peut_ack: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export class EvenementAgendaDto {
|
export class EvenementAgendaDto {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
id: string;
|
id: string;
|
||||||
@@ -70,27 +90,82 @@ export class EvenementAgendaDto {
|
|||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
id_placement: string;
|
id_placement: string;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({
|
||||||
|
description: 'Lot collectif (congé/arrêt/absence groupés)',
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
id_lot?: string | null;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({
|
||||||
|
description: 'Carte de collecte liée',
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
id_card_instance?: string | null;
|
||||||
|
|
||||||
@ApiProperty({ enum: TypeEvenementAgendaType })
|
@ApiProperty({ enum: TypeEvenementAgendaType })
|
||||||
type: TypeEvenementAgendaType;
|
type: TypeEvenementAgendaType;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty({ example: '2026-10-01' })
|
||||||
date_debut: string;
|
date_debut: string;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty({ example: '2026-10-05' })
|
||||||
date_fin: string;
|
date_fin: string;
|
||||||
|
|
||||||
@ApiProperty({ enum: StatutEvenementAgendaType })
|
@ApiPropertyOptional({
|
||||||
|
example: '18:19',
|
||||||
|
description: 'Heure métier (soin), HH:mm',
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
heure?: string | null;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
enum: StatutEvenementAgendaType,
|
||||||
|
description: 'Statut de cet événement (membre du lot si lot)',
|
||||||
|
})
|
||||||
statut: StatutEvenementAgendaType;
|
statut: StatutEvenementAgendaType;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({
|
||||||
|
enum: AgendaLotStatutType,
|
||||||
|
description: 'Statut global du lot ; null si hors lot',
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
statut_lot?: AgendaLotStatutType | null;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
enum: StatutEvenementAgendaType,
|
||||||
|
description:
|
||||||
|
'Statut à afficher pour l’utilisateur courant (peut différer du membre si lot refusé / nouvel accueil)',
|
||||||
|
})
|
||||||
|
statut_effectif: StatutEvenementAgendaType;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
expire_at: string;
|
expire_at: string;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ nullable: true })
|
||||||
|
verrouille_le?: string | null;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ nullable: true })
|
||||||
|
refuse_le?: string | null;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ nullable: true })
|
||||||
|
annule_le?: string | null;
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
cree_par?: string | null;
|
cree_par?: string | null;
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional({
|
||||||
|
description: 'Motif créateur ou texte de refus (sans nommer la famille)',
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
motif?: string | null;
|
motif?: string | null;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({
|
||||||
|
description:
|
||||||
|
'Libellé de refus anonymisé : « Refusé par une autre famille » / « Refusé par l\'autre parent »',
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
libelle_refus?: string | null;
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
id_enfant?: string | null;
|
id_enfant?: string | null;
|
||||||
|
|
||||||
@@ -106,6 +181,9 @@ export class EvenementAgendaDto {
|
|||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
nom_am?: string | null;
|
nom_am?: string | null;
|
||||||
|
|
||||||
|
@ApiProperty({ type: EvenementAgendaActionsDto })
|
||||||
|
actions: EvenementAgendaActionsDto;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
cree_le: string;
|
cree_le: string;
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ describe('EvenementsAgendaController (#172)', () => {
|
|||||||
let controller: EvenementsAgendaController;
|
let controller: EvenementsAgendaController;
|
||||||
const serviceMock = {
|
const serviceMock = {
|
||||||
lister: jest.fn(),
|
lister: jest.fn(),
|
||||||
|
getById: jest.fn(),
|
||||||
creer: jest.fn(),
|
creer: jest.fn(),
|
||||||
maj: jest.fn(),
|
maj: jest.fn(),
|
||||||
supprimer: jest.fn(),
|
supprimer: jest.fn(),
|
||||||
@@ -70,4 +71,14 @@ describe('EvenementsAgendaController (#172)', () => {
|
|||||||
dto,
|
dto,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getById délègue au service — #215', async () => {
|
||||||
|
serviceMock.getById.mockResolvedValue({ id: 'ev-1', actions: {} });
|
||||||
|
await controller.getById('u1', RoleType.PARENT, 'ev-1');
|
||||||
|
expect(serviceMock.getById).toHaveBeenCalledWith(
|
||||||
|
'ev-1',
|
||||||
|
'u1',
|
||||||
|
RoleType.PARENT,
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -76,6 +76,24 @@ export class EvenementsAgendaController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
@Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE)
|
||||||
|
@ApiOperation({
|
||||||
|
summary: 'Détail d’un événement agenda — #215',
|
||||||
|
description:
|
||||||
|
'DTO enrichi : id_lot, heure, statut_lot, statut_effectif, actions. ' +
|
||||||
|
'Lecture autorisée sur placement terminé (historique). ' +
|
||||||
|
'Aucun secret sur l’auteur d’un refus d’une autre famille.',
|
||||||
|
})
|
||||||
|
@ApiResponse({ status: 200, type: EvenementAgendaDto })
|
||||||
|
getById(
|
||||||
|
@User('id') userId: string,
|
||||||
|
@User('role') role: RoleType,
|
||||||
|
@Param('id', ParseUUIDPipe) id: string,
|
||||||
|
): Promise<EvenementAgendaDto> {
|
||||||
|
return this.evenementsAgendaService.getById(id, userId, role);
|
||||||
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE)
|
@Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE)
|
||||||
@ApiOperation({ summary: 'Créer une période d’absence / congé / arrêt — #172' })
|
@ApiOperation({ summary: 'Créer une période d’absence / congé / arrêt — #172' })
|
||||||
|
|||||||
@@ -165,4 +165,121 @@ describe('EvenementsAgendaService (#172)', () => {
|
|||||||
}),
|
}),
|
||||||
).rejects.toBeInstanceOf(BadRequestException);
|
).rejects.toBeInstanceOf(BadRequestException);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getById enrichit le DTO — #215', async () => {
|
||||||
|
absencesRepo.findOne.mockResolvedValue({
|
||||||
|
id: 'ev-1',
|
||||||
|
id_placement: 'pl-1',
|
||||||
|
id_lot: 'lot-1',
|
||||||
|
id_card_instance: 'card-1',
|
||||||
|
type: TypeEvenementAgendaType.SOIN_ENFANT,
|
||||||
|
date_debut: '2026-10-16',
|
||||||
|
date_fin: '2026-10-16',
|
||||||
|
heure: '18:19:00',
|
||||||
|
statut: StatutEvenementAgendaType.ACCEPTE,
|
||||||
|
expire_at: new Date('9999-12-31'),
|
||||||
|
cree_par: 'am-1',
|
||||||
|
motif: 'Piqûre',
|
||||||
|
cree_le: new Date(),
|
||||||
|
modifie_le: new Date(),
|
||||||
|
lot: null,
|
||||||
|
placement: {
|
||||||
|
enfantId: 'e-1',
|
||||||
|
amId: 'am-1',
|
||||||
|
child: { id: 'e-1', first_name: 'Léo' },
|
||||||
|
am: { user: { prenom: 'Marie', nom: 'AM' } },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
amChildrenRepo.findOne.mockResolvedValue({
|
||||||
|
id: 'pl-1',
|
||||||
|
amId: 'am-1',
|
||||||
|
enfantId: 'e-1',
|
||||||
|
date_fin: '2026-12-01',
|
||||||
|
});
|
||||||
|
parentsChildrenRepo.findOne.mockResolvedValue({
|
||||||
|
parentId: 'p-1',
|
||||||
|
enfantId: 'e-1',
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await service.getById('ev-1', 'p-1', RoleType.PARENT);
|
||||||
|
expect(res.id_lot).toBe('lot-1');
|
||||||
|
expect(res.id_card_instance).toBe('card-1');
|
||||||
|
expect(res.heure).toBe('18:19');
|
||||||
|
expect(res.statut_effectif).toBe(StatutEvenementAgendaType.ACCEPTE);
|
||||||
|
expect(res.actions.peut_ack).toBe(true);
|
||||||
|
expect(res.actions.peut_accepter_refuser).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getById autorise placement terminé (historique) — #215', async () => {
|
||||||
|
absencesRepo.findOne.mockResolvedValue({
|
||||||
|
id: 'ev-old',
|
||||||
|
id_placement: 'pl-ended',
|
||||||
|
type: TypeEvenementAgendaType.ABSENCE_ENFANT,
|
||||||
|
date_debut: '2026-01-01',
|
||||||
|
date_fin: '2026-01-05',
|
||||||
|
statut: StatutEvenementAgendaType.ACCEPTE,
|
||||||
|
expire_at: new Date('9999-12-31'),
|
||||||
|
cree_par: 'p-1',
|
||||||
|
cree_le: new Date(),
|
||||||
|
modifie_le: new Date(),
|
||||||
|
placement: {
|
||||||
|
enfantId: 'e-1',
|
||||||
|
amId: 'am-1',
|
||||||
|
child: { id: 'e-1', first_name: 'Léo' },
|
||||||
|
am: { user: { prenom: 'Marie', nom: 'AM' } },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
amChildrenRepo.findOne.mockResolvedValue({
|
||||||
|
id: 'pl-ended',
|
||||||
|
amId: 'am-1',
|
||||||
|
enfantId: 'e-1',
|
||||||
|
date_fin: '2026-06-01',
|
||||||
|
});
|
||||||
|
parentsChildrenRepo.findOne.mockResolvedValue({
|
||||||
|
parentId: 'p-1',
|
||||||
|
enfantId: 'e-1',
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await service.getById('ev-old', 'p-1', RoleType.PARENT);
|
||||||
|
expect(res.id).toBe('ev-old');
|
||||||
|
expect(res.actions.peut_modifier).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('libelle_refus n’expose pas l’auteur — #215', async () => {
|
||||||
|
absencesRepo.findOne.mockResolvedValue({
|
||||||
|
id: 'ev-ref',
|
||||||
|
id_placement: 'pl-1',
|
||||||
|
type: TypeEvenementAgendaType.CONGE_AM,
|
||||||
|
date_debut: '2026-11-01',
|
||||||
|
date_fin: '2026-11-10',
|
||||||
|
statut: StatutEvenementAgendaType.REFUSE,
|
||||||
|
expire_at: new Date(),
|
||||||
|
cree_par: 'am-1',
|
||||||
|
motif: 'Vacances scolaires',
|
||||||
|
cree_le: new Date(),
|
||||||
|
modifie_le: new Date(),
|
||||||
|
lot: { statut: 'refuse' },
|
||||||
|
placement: {
|
||||||
|
enfantId: 'e-1',
|
||||||
|
amId: 'am-1',
|
||||||
|
child: { id: 'e-1', first_name: 'Léo' },
|
||||||
|
am: { user: { prenom: 'Marie', nom: 'AM' } },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
amChildrenRepo.findOne.mockResolvedValue({
|
||||||
|
id: 'pl-1',
|
||||||
|
amId: 'am-1',
|
||||||
|
enfantId: 'e-1',
|
||||||
|
date_fin: null,
|
||||||
|
});
|
||||||
|
parentsChildrenRepo.findOne.mockResolvedValue({
|
||||||
|
parentId: 'p-1',
|
||||||
|
enfantId: 'e-1',
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await service.getById('ev-ref', 'p-1', RoleType.PARENT);
|
||||||
|
expect(res.libelle_refus).toBe('Refusé par une autre famille');
|
||||||
|
expect(res.statut_effectif).toBe(StatutEvenementAgendaType.REFUSE);
|
||||||
|
expect(res.libelle_refus).not.toMatch(/p-2|Dupont|famille B/i);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,11 +11,13 @@ import {
|
|||||||
StatutEvenementAgendaType,
|
StatutEvenementAgendaType,
|
||||||
TypeEvenementAgendaType,
|
TypeEvenementAgendaType,
|
||||||
} from 'src/entities/evenements_agenda.entity';
|
} from 'src/entities/evenements_agenda.entity';
|
||||||
|
import { AgendaLotStatutType } from 'src/entities/agenda_lots.entity';
|
||||||
import { AmChildren } from 'src/entities/am_children.entity';
|
import { AmChildren } from 'src/entities/am_children.entity';
|
||||||
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
||||||
import { RoleType } from 'src/entities/users.entity';
|
import { RoleType } from 'src/entities/users.entity';
|
||||||
import {
|
import {
|
||||||
EvenementAgendaDto,
|
EvenementAgendaDto,
|
||||||
|
EvenementAgendaActionsDto,
|
||||||
CreerEvenementAgendaDto,
|
CreerEvenementAgendaDto,
|
||||||
ListeEvenementsAgendaDto,
|
ListeEvenementsAgendaDto,
|
||||||
MajEvenementAgendaDto,
|
MajEvenementAgendaDto,
|
||||||
@@ -63,6 +65,7 @@ export class EvenementsAgendaService {
|
|||||||
.leftJoinAndSelect('placement.child', 'child')
|
.leftJoinAndSelect('placement.child', 'child')
|
||||||
.leftJoinAndSelect('placement.am', 'am')
|
.leftJoinAndSelect('placement.am', 'am')
|
||||||
.leftJoinAndSelect('am.user', 'amUser')
|
.leftJoinAndSelect('am.user', 'amUser')
|
||||||
|
.leftJoinAndSelect('ag.lot', 'lot')
|
||||||
.where('ag.id_placement IN (:...placementIds)', { placementIds })
|
.where('ag.id_placement IN (:...placementIds)', { placementIds })
|
||||||
.orderBy('ag.date_debut', 'DESC');
|
.orderBy('ag.date_debut', 'DESC');
|
||||||
|
|
||||||
@@ -80,7 +83,18 @@ export class EvenementsAgendaService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const rows = await qb.getMany();
|
const rows = await qb.getMany();
|
||||||
return { items: rows.map((r) => this.toDto(r)) };
|
return {
|
||||||
|
items: rows.map((r) => this.toDto(r, userId, role)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** GET :id — #215 */
|
||||||
|
async getById(
|
||||||
|
id: string,
|
||||||
|
userId: string,
|
||||||
|
role: RoleType,
|
||||||
|
): Promise<EvenementAgendaDto> {
|
||||||
|
return this.getByIdForUser(id, userId, role);
|
||||||
}
|
}
|
||||||
|
|
||||||
async creer(
|
async creer(
|
||||||
@@ -186,13 +200,22 @@ export class EvenementsAgendaService {
|
|||||||
): Promise<EvenementAgendaDto> {
|
): Promise<EvenementAgendaDto> {
|
||||||
const row = await this.absencesRepo.findOne({
|
const row = await this.absencesRepo.findOne({
|
||||||
where: { id },
|
where: { id },
|
||||||
relations: ['placement', 'placement.child', 'placement.am', 'placement.am.user'],
|
relations: [
|
||||||
|
'placement',
|
||||||
|
'placement.child',
|
||||||
|
'placement.am',
|
||||||
|
'placement.am.user',
|
||||||
|
'lot',
|
||||||
|
],
|
||||||
});
|
});
|
||||||
if (!row) {
|
if (!row) {
|
||||||
throw new NotFoundException('Absence introuvable');
|
throw new NotFoundException('Événement introuvable');
|
||||||
}
|
}
|
||||||
await this.assertCanAccessPlacement(userId, role, row.id_placement);
|
// Lecture : historique autorisé même si placement terminé (B1 / prépare B3)
|
||||||
return this.toDto(row);
|
await this.assertCanAccessPlacement(userId, role, row.id_placement, {
|
||||||
|
allowEnded: true,
|
||||||
|
});
|
||||||
|
return this.toDto(row, userId, role);
|
||||||
}
|
}
|
||||||
|
|
||||||
private statutInitial(type: TypeEvenementAgendaType): StatutEvenementAgendaType {
|
private statutInitial(type: TypeEvenementAgendaType): StatutEvenementAgendaType {
|
||||||
@@ -367,12 +390,19 @@ export class EvenementsAgendaService {
|
|||||||
userId: string,
|
userId: string,
|
||||||
role: RoleType,
|
role: RoleType,
|
||||||
placementId: string,
|
placementId: string,
|
||||||
|
opts?: { allowEnded?: boolean },
|
||||||
): Promise<AmChildren> {
|
): Promise<AmChildren> {
|
||||||
const placement = await this.amChildrenRepo.findOne({
|
const placement = await this.amChildrenRepo.findOne({
|
||||||
where: { id: placementId, date_fin: IsNull() },
|
where: opts?.allowEnded
|
||||||
|
? { id: placementId }
|
||||||
|
: { id: placementId, date_fin: IsNull() },
|
||||||
});
|
});
|
||||||
if (!placement) {
|
if (!placement) {
|
||||||
throw new NotFoundException('Placement / couple introuvable ou inactif');
|
throw new NotFoundException(
|
||||||
|
opts?.allowEnded
|
||||||
|
? 'Placement / couple introuvable'
|
||||||
|
: 'Placement / couple introuvable ou inactif',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role === RoleType.ASSISTANTE_MATERNELLE) {
|
if (role === RoleType.ASSISTANTE_MATERNELLE) {
|
||||||
@@ -397,26 +427,187 @@ export class EvenementsAgendaService {
|
|||||||
throw new ForbiddenException('Rôle non autorisé');
|
throw new ForbiddenException('Rôle non autorisé');
|
||||||
}
|
}
|
||||||
|
|
||||||
private toDto(row: EvenementsAgenda): EvenementAgendaDto {
|
private toDto(
|
||||||
|
row: EvenementsAgenda,
|
||||||
|
userId?: string,
|
||||||
|
role?: RoleType,
|
||||||
|
): EvenementAgendaDto {
|
||||||
const child = row.placement?.child;
|
const child = row.placement?.child;
|
||||||
const amUser = row.placement?.am?.user;
|
const amUser = row.placement?.am?.user;
|
||||||
|
const statutLot = (row.lot?.statut as AgendaLotStatutType | undefined) ?? null;
|
||||||
|
const statutEffectif = this.statutEffectif(row, statutLot);
|
||||||
return {
|
return {
|
||||||
id: row.id,
|
id: row.id,
|
||||||
id_placement: row.id_placement,
|
id_placement: row.id_placement,
|
||||||
|
id_lot: row.id_lot ?? null,
|
||||||
|
id_card_instance: row.id_card_instance ?? null,
|
||||||
type: row.type,
|
type: row.type,
|
||||||
date_debut: row.date_debut,
|
date_debut: row.date_debut,
|
||||||
date_fin: row.date_fin,
|
date_fin: row.date_fin,
|
||||||
|
heure: this.formatHeure(row.heure),
|
||||||
statut: row.statut,
|
statut: row.statut,
|
||||||
|
statut_lot: statutLot,
|
||||||
|
statut_effectif: statutEffectif,
|
||||||
expire_at: row.expire_at?.toISOString?.() ?? String(row.expire_at),
|
expire_at: row.expire_at?.toISOString?.() ?? String(row.expire_at),
|
||||||
|
verrouille_le: row.verrouille_le
|
||||||
|
? row.verrouille_le.toISOString?.() ?? String(row.verrouille_le)
|
||||||
|
: null,
|
||||||
|
refuse_le: row.refuse_le
|
||||||
|
? row.refuse_le.toISOString?.() ?? String(row.refuse_le)
|
||||||
|
: null,
|
||||||
|
annule_le: row.annule_le
|
||||||
|
? row.annule_le.toISOString?.() ?? String(row.annule_le)
|
||||||
|
: null,
|
||||||
cree_par: row.cree_par ?? null,
|
cree_par: row.cree_par ?? null,
|
||||||
motif: row.motif ?? null,
|
motif: row.motif ?? null,
|
||||||
|
libelle_refus: this.libelleRefus(row, statutLot, userId, role),
|
||||||
id_enfant: child?.id ?? row.placement?.enfantId ?? null,
|
id_enfant: child?.id ?? row.placement?.enfantId ?? null,
|
||||||
prenom_enfant: child?.first_name ?? null,
|
prenom_enfant: child?.first_name ?? null,
|
||||||
id_am: row.placement?.amId ?? null,
|
id_am: row.placement?.amId ?? null,
|
||||||
prenom_am: amUser?.prenom ?? null,
|
prenom_am: amUser?.prenom ?? null,
|
||||||
nom_am: amUser?.nom ?? null,
|
nom_am: amUser?.nom ?? null,
|
||||||
|
actions: this.actionsPour(row, statutLot, userId, role),
|
||||||
cree_le: row.cree_le?.toISOString?.() ?? String(row.cree_le),
|
cree_le: row.cree_le?.toISOString?.() ?? String(row.cree_le),
|
||||||
modifie_le: row.modifie_le?.toISOString?.() ?? String(row.modifie_le),
|
modifie_le: row.modifie_le?.toISOString?.() ?? String(row.modifie_le),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private formatHeure(heure?: string | null): string | null {
|
||||||
|
if (!heure) return null;
|
||||||
|
const s = String(heure);
|
||||||
|
return s.length >= 5 ? s.slice(0, 5) : s;
|
||||||
|
}
|
||||||
|
|
||||||
|
private statutEffectif(
|
||||||
|
row: EvenementsAgenda,
|
||||||
|
statutLot: AgendaLotStatutType | null,
|
||||||
|
): StatutEvenementAgendaType {
|
||||||
|
if (row.statut === StatutEvenementAgendaType.ANNULE) {
|
||||||
|
return StatutEvenementAgendaType.ANNULE;
|
||||||
|
}
|
||||||
|
if (statutLot === AgendaLotStatutType.ANNULE) {
|
||||||
|
return StatutEvenementAgendaType.ANNULE;
|
||||||
|
}
|
||||||
|
if (statutLot === AgendaLotStatutType.REFUSE) {
|
||||||
|
return StatutEvenementAgendaType.REFUSE;
|
||||||
|
}
|
||||||
|
return row.statut;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anonymise l’auteur du refus : jamais le nom d’une autre famille.
|
||||||
|
* B1 : si refusé et viewer ≠ créateur → « autre famille » ;
|
||||||
|
* si viewer est parent créateur/foyer et motif présent → « autre parent » pour co-parent
|
||||||
|
* (sans id répondant en B1 : défaut « autre famille » pour parent destinataire).
|
||||||
|
*/
|
||||||
|
private libelleRefus(
|
||||||
|
row: EvenementsAgenda,
|
||||||
|
statutLot: AgendaLotStatutType | null,
|
||||||
|
userId?: string,
|
||||||
|
role?: RoleType,
|
||||||
|
): string | null {
|
||||||
|
const refuse =
|
||||||
|
row.statut === StatutEvenementAgendaType.REFUSE ||
|
||||||
|
statutLot === AgendaLotStatutType.REFUSE;
|
||||||
|
if (!refuse) return null;
|
||||||
|
if (!userId || !role) return 'Refusé';
|
||||||
|
if (role === RoleType.ASSISTANTE_MATERNELLE) {
|
||||||
|
return 'Refusé par une famille';
|
||||||
|
}
|
||||||
|
// Parent : ne jamais citer quelle famille. Si ce n’est pas le créateur AM, message générique.
|
||||||
|
if (row.cree_par && row.cree_par === userId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return 'Refusé par une autre famille';
|
||||||
|
}
|
||||||
|
|
||||||
|
private actionsPour(
|
||||||
|
row: EvenementsAgenda,
|
||||||
|
statutLot: AgendaLotStatutType | null,
|
||||||
|
userId?: string,
|
||||||
|
role?: RoleType,
|
||||||
|
): EvenementAgendaActionsDto {
|
||||||
|
const none: EvenementAgendaActionsDto = {
|
||||||
|
peut_modifier: false,
|
||||||
|
peut_supprimer: false,
|
||||||
|
peut_accepter_refuser: false,
|
||||||
|
peut_ack: false,
|
||||||
|
};
|
||||||
|
if (!userId || !role) return none;
|
||||||
|
if (
|
||||||
|
row.statut === StatutEvenementAgendaType.ANNULE ||
|
||||||
|
statutLot === AgendaLotStatutType.ANNULE
|
||||||
|
) {
|
||||||
|
return none;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isCreator = row.cree_par === userId;
|
||||||
|
const today = new Date().toISOString().slice(0, 10);
|
||||||
|
const notStarted = row.date_debut > today;
|
||||||
|
const enAttente =
|
||||||
|
row.statut === StatutEvenementAgendaType.EN_ATTENTE ||
|
||||||
|
statutLot === AgendaLotStatutType.EN_ATTENTE;
|
||||||
|
const refuse =
|
||||||
|
row.statut === StatutEvenementAgendaType.REFUSE ||
|
||||||
|
statutLot === AgendaLotStatutType.REFUSE;
|
||||||
|
const accepte =
|
||||||
|
row.statut === StatutEvenementAgendaType.ACCEPTE ||
|
||||||
|
statutLot === AgendaLotStatutType.ACCEPTE;
|
||||||
|
|
||||||
|
if (role === RoleType.ASSISTANTE_MATERNELLE && isCreator) {
|
||||||
|
const congeFuturModifiable =
|
||||||
|
row.type === TypeEvenementAgendaType.CONGE_AM &&
|
||||||
|
accepte &&
|
||||||
|
notStarted;
|
||||||
|
return {
|
||||||
|
peut_modifier:
|
||||||
|
enAttente || refuse || congeFuturModifiable ||
|
||||||
|
(row.type !== TypeEvenementAgendaType.CONGE_AM &&
|
||||||
|
row.type !== TypeEvenementAgendaType.SOIN_ENFANT &&
|
||||||
|
accepte),
|
||||||
|
peut_supprimer:
|
||||||
|
enAttente ||
|
||||||
|
refuse ||
|
||||||
|
(row.type === TypeEvenementAgendaType.CONGE_AM &&
|
||||||
|
accepte &&
|
||||||
|
notStarted) ||
|
||||||
|
row.type === TypeEvenementAgendaType.ARRET_MALADIE_AM ||
|
||||||
|
row.type === TypeEvenementAgendaType.SOIN_ENFANT,
|
||||||
|
peut_accepter_refuser: false,
|
||||||
|
peut_ack: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (role === RoleType.PARENT && !isCreator) {
|
||||||
|
const congeEnAttente =
|
||||||
|
row.type === TypeEvenementAgendaType.CONGE_AM &&
|
||||||
|
row.statut === StatutEvenementAgendaType.EN_ATTENTE &&
|
||||||
|
statutLot !== AgendaLotStatutType.REFUSE &&
|
||||||
|
statutLot !== AgendaLotStatutType.ANNULE;
|
||||||
|
const arretAck =
|
||||||
|
row.type === TypeEvenementAgendaType.ARRET_MALADIE_AM;
|
||||||
|
const soinAck = row.type === TypeEvenementAgendaType.SOIN_ENFANT;
|
||||||
|
return {
|
||||||
|
peut_modifier: false,
|
||||||
|
peut_supprimer: false,
|
||||||
|
peut_accepter_refuser: congeEnAttente,
|
||||||
|
peut_ack: arretAck || soinAck,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
role === RoleType.PARENT &&
|
||||||
|
isCreator &&
|
||||||
|
row.type === TypeEvenementAgendaType.ABSENCE_ENFANT
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
peut_modifier: true,
|
||||||
|
peut_supprimer: true,
|
||||||
|
peut_accepter_refuser: false,
|
||||||
|
peut_ack: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user