feat(#216): Agenda B2 — soft-cancel + matrice + cron

Closes #216

Co-authored-by: Julien Martin <julien.martin@ptits-pas.fr>
This commit was merged in pull request #234.
This commit is contained in:
2026-10-16 15:07:14 +00:00
committed by jmartin
parent 0ac8526053
commit df130aedd9
11 changed files with 948 additions and 65 deletions
@@ -0,0 +1,38 @@
import { Injectable, Logger } from '@nestjs/common';
import { Cron, CronExpression } from '@nestjs/schedule';
import { EvenementsAgendaService } from './evenements-agenda.service';
/**
* Échéances Agenda (#216) : auto-valid congés J+7, soft-cancel refusés J+7.
* Idempotent ; rattrapage au redémarrage via le prochain tick.
*/
@Injectable()
export class AgendaExpirationCron {
private readonly logger = new Logger(AgendaExpirationCron.name);
private running = false;
constructor(private readonly evenements: EvenementsAgendaService) {}
@Cron(CronExpression.EVERY_HOUR)
async tick(): Promise<void> {
await this.runOnce();
}
/** Exposé pour tests / appel manuel (double-appel = no-op côté rows déjà traités). */
async runOnce(
now = new Date(),
): Promise<{ autoValid: number; softCancel: number }> {
if (this.running) {
this.logger.debug('Cron agenda déjà en cours — skip');
return { autoValid: 0, softCancel: 0 };
}
this.running = true;
try {
const autoValid = await this.evenements.autoValiderCongesExpires(now);
const softCancel = await this.evenements.softCancelRefusesExpires(now);
return { autoValid, softCancel };
} finally {
this.running = false;
}
}
}