Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f547f76b1c |
@@ -47,16 +47,18 @@ export class EvenementsAgendaController {
|
||||
@Get()
|
||||
@Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE)
|
||||
@ApiOperation({
|
||||
summary: 'Lister les absences / congés / arrêts — ticket #205 / ex-#172',
|
||||
summary: 'Lister les événements agenda — #217 / #205',
|
||||
description:
|
||||
'Sans placementId : tous les placements du user (parent = famille multi-AM ; AM = tous accueils). ' +
|
||||
'Avec placementId : un couple enfant–AM.',
|
||||
'Sans placementId : tous les placements du user (actifs **et** terminés — historique). ' +
|
||||
'Avec placementId : un couple enfant–AM (terminé OK). ' +
|
||||
'Filtres from/to inclusifs (chevauchement). Annulés exclus sauf si statut=annule. ' +
|
||||
'Dates YYYY-MM-DD calendaires (DST-safe).',
|
||||
})
|
||||
@ApiQuery({ name: 'placementId', required: false })
|
||||
@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' })
|
||||
@ApiQuery({ name: 'from', required: false, description: 'YYYY-MM-DD (inclus)' })
|
||||
@ApiQuery({ name: 'to', required: false, description: 'YYYY-MM-DD (inclus)' })
|
||||
@ApiResponse({ status: 200, type: ListeEvenementsAgendaDto })
|
||||
lister(
|
||||
@User('id') userId: string,
|
||||
|
||||
@@ -245,6 +245,96 @@ describe('EvenementsAgendaService (#172)', () => {
|
||||
expect(res.actions.peut_modifier).toBe(true);
|
||||
});
|
||||
|
||||
describe('lister — #217', () => {
|
||||
const andWhere = jest.fn().mockReturnThis();
|
||||
const qb = {
|
||||
leftJoinAndSelect: jest.fn().mockReturnThis(),
|
||||
where: jest.fn().mockReturnThis(),
|
||||
andWhere,
|
||||
orderBy: jest.fn().mockReturnThis(),
|
||||
getMany: jest.fn().mockResolvedValue([]),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
andWhere.mockClear();
|
||||
absencesRepo.createQueryBuilder.mockReturnValue(qb);
|
||||
amChildrenRepo.find.mockResolvedValue([{ id: 'pl-1' }, { id: 'pl-ended' }]);
|
||||
});
|
||||
|
||||
it('from > to → BadRequest', async () => {
|
||||
await expect(
|
||||
service.lister('am-1', RoleType.ASSISTANTE_MATERNELLE, {
|
||||
from: '2026-10-31',
|
||||
to: '2026-10-01',
|
||||
}),
|
||||
).rejects.toBeInstanceOf(BadRequestException);
|
||||
});
|
||||
|
||||
it('date invalide (31 nov) → BadRequest', async () => {
|
||||
await expect(
|
||||
service.lister('am-1', RoleType.ASSISTANTE_MATERNELLE, {
|
||||
from: '2026-11-31',
|
||||
to: '2026-12-01',
|
||||
}),
|
||||
).rejects.toBeInstanceOf(BadRequestException);
|
||||
});
|
||||
|
||||
it('exclut les annulés par défaut + bornes inclusives', async () => {
|
||||
await service.lister('am-1', RoleType.ASSISTANTE_MATERNELLE, {
|
||||
from: '2026-10-01',
|
||||
to: '2026-10-31',
|
||||
});
|
||||
expect(amChildrenRepo.find).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
where: expect.objectContaining({ amId: 'am-1' }),
|
||||
}),
|
||||
);
|
||||
// pas de date_fin: IsNull() → historique inclus
|
||||
const whereArg = amChildrenRepo.find.mock.calls[0][0].where;
|
||||
expect(whereArg.date_fin).toBeUndefined();
|
||||
expect(andWhere).toHaveBeenCalledWith('ag.statut != :annule', {
|
||||
annule: StatutEvenementAgendaType.ANNULE,
|
||||
});
|
||||
expect(andWhere).toHaveBeenCalledWith('ag.date_fin >= :from', {
|
||||
from: '2026-10-01',
|
||||
});
|
||||
expect(andWhere).toHaveBeenCalledWith('ag.date_debut <= :to', {
|
||||
to: '2026-10-31',
|
||||
});
|
||||
});
|
||||
|
||||
it('DST octobre : bornes calendaires acceptées (2026-10-25)', async () => {
|
||||
// dernier dimanche d’octobre 2026 = 25 oct. — strings YYYY-MM-DD, pas Date UTC
|
||||
await expect(
|
||||
service.lister('am-1', RoleType.ASSISTANTE_MATERNELLE, {
|
||||
from: '2026-10-25',
|
||||
to: '2026-10-26',
|
||||
}),
|
||||
).resolves.toEqual({ items: [] });
|
||||
expect(andWhere).toHaveBeenCalledWith('ag.date_fin >= :from', {
|
||||
from: '2026-10-25',
|
||||
});
|
||||
});
|
||||
|
||||
it('année bissextile : 2024-02-29 valide', async () => {
|
||||
await expect(
|
||||
service.lister('am-1', RoleType.ASSISTANTE_MATERNELLE, {
|
||||
from: '2024-02-29',
|
||||
to: '2024-03-01',
|
||||
}),
|
||||
).resolves.toEqual({ items: [] });
|
||||
});
|
||||
|
||||
it('2025-02-29 invalide (non bissextile)', async () => {
|
||||
await expect(
|
||||
service.lister('am-1', RoleType.ASSISTANTE_MATERNELLE, {
|
||||
from: '2025-02-29',
|
||||
to: '2025-03-01',
|
||||
}),
|
||||
).rejects.toBeInstanceOf(BadRequestException);
|
||||
});
|
||||
});
|
||||
|
||||
it('libelle_refus n’expose pas l’auteur — #215', async () => {
|
||||
absencesRepo.findOne.mockResolvedValue({
|
||||
id: 'ev-ref',
|
||||
|
||||
@@ -50,10 +50,14 @@ export class EvenementsAgendaService {
|
||||
to?: string;
|
||||
},
|
||||
): Promise<ListeEvenementsAgendaDto> {
|
||||
this.assertDateRange(opts.from, opts.to);
|
||||
|
||||
// Agenda : historique inclus (placements terminés) — #217
|
||||
const placementIds = await this.resolvePlacementIds(
|
||||
userId,
|
||||
role,
|
||||
opts.placementId,
|
||||
{ includeEnded: true },
|
||||
);
|
||||
if (placementIds.length === 0) {
|
||||
return { items: [] };
|
||||
@@ -72,9 +76,15 @@ export class EvenementsAgendaService {
|
||||
if (opts.type) {
|
||||
qb.andWhere('ag.type = :type', { type: opts.type });
|
||||
}
|
||||
// Exclusion des annulés par défaut ; statut=annule demande explicitement les annulés
|
||||
if (opts.statut) {
|
||||
qb.andWhere('ag.statut = :statut', { statut: opts.statut });
|
||||
} else {
|
||||
qb.andWhere('ag.statut != :annule', {
|
||||
annule: StatutEvenementAgendaType.ANNULE,
|
||||
});
|
||||
}
|
||||
// Chevauchement inclusif : date_debut <= to AND date_fin >= from
|
||||
if (opts.from) {
|
||||
qb.andWhere('ag.date_fin >= :from', { from: opts.from });
|
||||
}
|
||||
@@ -244,6 +254,33 @@ export class EvenementsAgendaService {
|
||||
}
|
||||
}
|
||||
|
||||
/** Bornes calendaires YYYY-MM-DD (comparaison lexicographique = calendaire, DST-safe). #217 */
|
||||
private assertDateRange(from?: string, to?: string): void {
|
||||
if (from) this.assertCalendarDate(from, 'from');
|
||||
if (to) this.assertCalendarDate(to, 'to');
|
||||
if (from && to && from > to) {
|
||||
throw new BadRequestException('from doit être inférieure ou égale à to');
|
||||
}
|
||||
}
|
||||
|
||||
private assertCalendarDate(value: string, field: string): void {
|
||||
if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
||||
throw new BadRequestException(
|
||||
`${field} doit être une date YYYY-MM-DD`,
|
||||
);
|
||||
}
|
||||
const [y, m, d] = value.split('-').map(Number);
|
||||
// UTC : évite qu’un parse local fasse glisser le jour à l’heure d’hiver
|
||||
const dt = new Date(Date.UTC(y, m - 1, d));
|
||||
if (
|
||||
dt.getUTCFullYear() !== y ||
|
||||
dt.getUTCMonth() !== m - 1 ||
|
||||
dt.getUTCDate() !== d
|
||||
) {
|
||||
throw new BadRequestException(`${field} n’est pas une date calendaire valide`);
|
||||
}
|
||||
}
|
||||
|
||||
private assertCanCreateType(role: RoleType, type: TypeEvenementAgendaType): void {
|
||||
if (role === RoleType.PARENT) {
|
||||
if (type !== TypeEvenementAgendaType.ABSENCE_ENFANT) {
|
||||
@@ -355,9 +392,12 @@ export class EvenementsAgendaService {
|
||||
userId: string,
|
||||
role: RoleType,
|
||||
placementId?: string,
|
||||
opts?: { includeEnded?: boolean },
|
||||
): Promise<string[]> {
|
||||
if (placementId) {
|
||||
await this.assertCanAccessPlacement(userId, role, placementId);
|
||||
await this.assertCanAccessPlacement(userId, role, placementId, {
|
||||
allowEnded: opts?.includeEnded === true,
|
||||
});
|
||||
return [placementId];
|
||||
}
|
||||
|
||||
@@ -369,7 +409,9 @@ export class EvenementsAgendaService {
|
||||
const enfantIds = liens.map((l) => l.enfantId);
|
||||
if (enfantIds.length === 0) return [];
|
||||
const placements = await this.amChildrenRepo.find({
|
||||
where: { enfantId: In(enfantIds), date_fin: IsNull() },
|
||||
where: opts?.includeEnded
|
||||
? { enfantId: In(enfantIds) }
|
||||
: { enfantId: In(enfantIds), date_fin: IsNull() },
|
||||
select: ['id'],
|
||||
});
|
||||
return placements.map((p) => p.id);
|
||||
@@ -377,7 +419,9 @@ export class EvenementsAgendaService {
|
||||
|
||||
if (role === RoleType.ASSISTANTE_MATERNELLE) {
|
||||
const placements = await this.amChildrenRepo.find({
|
||||
where: { amId: userId, date_fin: IsNull() },
|
||||
where: opts?.includeEnded
|
||||
? { amId: userId }
|
||||
: { amId: userId, date_fin: IsNull() },
|
||||
select: ['id'],
|
||||
});
|
||||
return placements.map((p) => p.id);
|
||||
|
||||
Reference in New Issue
Block a user