feat(#206): backend cartes rose soin_enfant (3 sous-types, instant T, correction 24h)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -136,23 +136,76 @@ export class CardsService {
|
||||
let absenceId = dto.id_evenement;
|
||||
const absenceType = this.mapAbsenceType(dto.type_code);
|
||||
|
||||
let motif = dto.motif ?? null;
|
||||
let finalPayload = {
|
||||
date_debut: dto.date_debut,
|
||||
date_fin: dto.date_fin,
|
||||
motif,
|
||||
...(dto.payload ?? {}),
|
||||
};
|
||||
|
||||
if (dto.type_code === 'soin_enfant') {
|
||||
const p = dto.payload;
|
||||
if (!p || !p.sous_type || !p.heure_releve) {
|
||||
throw new BadRequestException('sous_type et heure_releve requis pour soin_enfant');
|
||||
}
|
||||
if (!/^([01]\d|2[0-3]):([0-5]\d)$/.test(p.heure_releve)) {
|
||||
throw new BadRequestException('Format heure_releve invalide (HH:mm)');
|
||||
}
|
||||
|
||||
if (p.sous_type === 'fievre') {
|
||||
if (typeof p.temperature_c !== 'number' || p.temperature_c < 34.0 || p.temperature_c > 43.0) {
|
||||
throw new BadRequestException('temperature_c invalide (34.0 - 43.0)');
|
||||
}
|
||||
motif = `${p.temperature_c.toFixed(1).replace('.', ',')} °C à ${p.heure_releve}`;
|
||||
if (p.medicament_donne && typeof p.medicament_donne === 'string' && p.medicament_donne.trim()) {
|
||||
motif += ` (Médicament : ${p.medicament_donne.trim()})`;
|
||||
}
|
||||
} else if (p.sous_type === 'bobo') {
|
||||
const natures = ['chute', 'coup', 'egratignure', 'piqure', 'brulure', 'autre'];
|
||||
if (!natures.includes(p.bobo_nature)) {
|
||||
throw new BadRequestException('bobo_nature invalide');
|
||||
}
|
||||
motif = `Bobo (${p.bobo_nature}) à ${p.heure_releve}`;
|
||||
if (p.description && typeof p.description === 'string' && p.description.trim()) {
|
||||
const desc = p.description.trim();
|
||||
if (desc.length > 120) throw new BadRequestException('description trop longue (max 120)');
|
||||
motif += ` : ${desc.length > 30 ? desc.substring(0, 30) + '...' : desc}`;
|
||||
}
|
||||
} else if (p.sous_type === 'medicament') {
|
||||
if (!p.medicament_nom || typeof p.medicament_nom !== 'string' || !p.medicament_nom.trim()) {
|
||||
throw new BadRequestException('medicament_nom requis');
|
||||
}
|
||||
motif = `Médicament (${p.medicament_nom.trim()}) à ${p.heure_releve}`;
|
||||
if (p.contexte && typeof p.contexte === 'string' && p.contexte.trim()) {
|
||||
if (p.contexte.trim().length > 120) throw new BadRequestException('contexte trop long (max 120)');
|
||||
}
|
||||
} else {
|
||||
throw new BadRequestException('sous_type invalide pour soin_enfant');
|
||||
}
|
||||
finalPayload.motif = motif;
|
||||
}
|
||||
|
||||
if (operation === CardOperationType.CREATE) {
|
||||
const absence = await this.evenementsService.creer(userId, role, {
|
||||
id_placement: dto.id_placement,
|
||||
type: absenceType,
|
||||
date_debut: dto.date_debut,
|
||||
date_fin: dto.date_fin,
|
||||
motif: dto.motif,
|
||||
motif: motif ?? undefined,
|
||||
});
|
||||
absenceId = absence.id;
|
||||
} else {
|
||||
if (dto.type_code === 'soin_enfant') {
|
||||
throw new BadRequestException('operation=update interdite pour soin_enfant');
|
||||
}
|
||||
if (!absenceId) {
|
||||
throw new BadRequestException('id_evenement requis pour operation=update');
|
||||
}
|
||||
await this.evenementsService.maj(userId, role, absenceId, {
|
||||
date_debut: dto.date_debut,
|
||||
date_fin: dto.date_fin,
|
||||
motif: dto.motif,
|
||||
motif: motif ?? undefined,
|
||||
// Congé accepté modifié → repasse en attente via cartes respond flow;
|
||||
// pour absence enfant update immédiat déjà fait.
|
||||
...(dto.type_code === 'conge_am'
|
||||
@@ -173,11 +226,7 @@ export class CardsService {
|
||||
cree_par: userId,
|
||||
operation,
|
||||
statut: statutInitial,
|
||||
payload: {
|
||||
date_debut: dto.date_debut,
|
||||
date_fin: dto.date_fin,
|
||||
motif: dto.motif ?? null,
|
||||
},
|
||||
payload: finalPayload,
|
||||
purge_at: this.purgeAt(type.retention_days, statutInitial),
|
||||
});
|
||||
const saved = await this.cardsRepo.save(card);
|
||||
@@ -280,11 +329,19 @@ export class CardsService {
|
||||
if (card.cree_par !== userId) {
|
||||
throw new ForbiddenException('Seul le créateur peut modifier cette carte');
|
||||
}
|
||||
if (
|
||||
card.statut !== CardInstanceStatutType.OUVERTE &&
|
||||
card.statut !== CardInstanceStatutType.REFUSEE
|
||||
) {
|
||||
throw new BadRequestException('Carte non modifiable dans cet état');
|
||||
|
||||
if (card.type_code === 'soin_enfant') {
|
||||
const msSinceCreation = Date.now() - new Date(card.cree_le).getTime();
|
||||
if (msSinceCreation > 24 * 60 * 60 * 1000) {
|
||||
throw new BadRequestException('Délai de correction de 24h dépassé');
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
card.statut !== CardInstanceStatutType.OUVERTE &&
|
||||
card.statut !== CardInstanceStatutType.REFUSEE
|
||||
) {
|
||||
throw new BadRequestException('Carte non modifiable dans cet état');
|
||||
}
|
||||
}
|
||||
|
||||
const debut =
|
||||
@@ -294,21 +351,79 @@ export class CardsService {
|
||||
throw new BadRequestException('Dates invalides');
|
||||
}
|
||||
|
||||
let motif = dto.motif ?? card.payload?.['motif'] ?? null;
|
||||
let finalPayload = {
|
||||
...card.payload,
|
||||
date_debut: debut,
|
||||
date_fin: fin,
|
||||
...(dto.payload ?? {}),
|
||||
};
|
||||
|
||||
if (card.type_code === 'soin_enfant') {
|
||||
const p = finalPayload;
|
||||
if (!p || !p.sous_type || !p.heure_releve) {
|
||||
throw new BadRequestException('sous_type et heure_releve requis pour soin_enfant');
|
||||
}
|
||||
if (!/^([01]\d|2[0-3]):([0-5]\d)$/.test(p.heure_releve)) {
|
||||
throw new BadRequestException('Format heure_releve invalide (HH:mm)');
|
||||
}
|
||||
|
||||
if (p.sous_type === 'fievre') {
|
||||
if (typeof p.temperature_c !== 'number' || p.temperature_c < 34.0 || p.temperature_c > 43.0) {
|
||||
throw new BadRequestException('temperature_c invalide (34.0 - 43.0)');
|
||||
}
|
||||
motif = `${p.temperature_c.toFixed(1).replace('.', ',')} °C à ${p.heure_releve}`;
|
||||
if (p.medicament_donne && typeof p.medicament_donne === 'string' && p.medicament_donne.trim()) {
|
||||
motif += ` (Médicament : ${p.medicament_donne.trim()})`;
|
||||
}
|
||||
} else if (p.sous_type === 'bobo') {
|
||||
const natures = ['chute', 'coup', 'egratignure', 'piqure', 'brulure', 'autre'];
|
||||
if (!natures.includes(p.bobo_nature)) {
|
||||
throw new BadRequestException('bobo_nature invalide');
|
||||
}
|
||||
motif = `Bobo (${p.bobo_nature}) à ${p.heure_releve}`;
|
||||
if (p.description && typeof p.description === 'string' && p.description.trim()) {
|
||||
const desc = p.description.trim();
|
||||
if (desc.length > 120) throw new BadRequestException('description trop longue (max 120)');
|
||||
motif += ` : ${desc.length > 30 ? desc.substring(0, 30) + '...' : desc}`;
|
||||
}
|
||||
} else if (p.sous_type === 'medicament') {
|
||||
if (!p.medicament_nom || typeof p.medicament_nom !== 'string' || !p.medicament_nom.trim()) {
|
||||
throw new BadRequestException('medicament_nom requis');
|
||||
}
|
||||
motif = `Médicament (${p.medicament_nom.trim()}) à ${p.heure_releve}`;
|
||||
if (p.contexte && typeof p.contexte === 'string' && p.contexte.trim()) {
|
||||
if (p.contexte.trim().length > 120) throw new BadRequestException('contexte trop long (max 120)');
|
||||
}
|
||||
} else {
|
||||
throw new BadRequestException('sous_type invalide pour soin_enfant');
|
||||
}
|
||||
finalPayload.motif = motif;
|
||||
|
||||
const hist = Array.isArray(card.payload?.['historique']) ? card.payload['historique'] : [];
|
||||
const oldPayload = { ...card.payload };
|
||||
delete oldPayload.historique;
|
||||
hist.push({
|
||||
...oldPayload,
|
||||
corrige_le: new Date().toISOString(),
|
||||
corrige_par: userId,
|
||||
});
|
||||
finalPayload.historique = hist;
|
||||
finalPayload.corrige_le = new Date().toISOString();
|
||||
} else {
|
||||
finalPayload.motif = motif;
|
||||
}
|
||||
|
||||
if (card.id_evenement) {
|
||||
await this.evenementsService.maj(userId, role, card.id_evenement, {
|
||||
date_debut: debut,
|
||||
date_fin: fin,
|
||||
motif: dto.motif,
|
||||
statut: StatutEvenementAgendaType.EN_ATTENTE,
|
||||
motif: motif ?? undefined,
|
||||
...(card.type_code !== 'soin_enfant' ? { statut: StatutEvenementAgendaType.EN_ATTENTE } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
card.payload = {
|
||||
...card.payload,
|
||||
date_debut: debut,
|
||||
date_fin: fin,
|
||||
motif: dto.motif ?? card.payload?.['motif'] ?? null,
|
||||
};
|
||||
card.payload = finalPayload;
|
||||
card.statut = CardInstanceStatutType.OUVERTE;
|
||||
card.purge_at = this.purgeAt(card.type.retention_days, card.statut);
|
||||
await this.cardsRepo.manager.query(
|
||||
@@ -332,16 +447,25 @@ export class CardsService {
|
||||
if (card.cree_par !== userId) {
|
||||
throw new ForbiddenException('Seul le créateur peut supprimer cette carte');
|
||||
}
|
||||
|
||||
if (card.type_code === 'soin_enfant') {
|
||||
const msSinceCreation = Date.now() - new Date(card.cree_le).getTime();
|
||||
if (msSinceCreation > 24 * 60 * 60 * 1000) {
|
||||
throw new BadRequestException('Délai de correction de 24h dépassé, suppression impossible');
|
||||
}
|
||||
}
|
||||
|
||||
const audienceIds = await this.audienceUserIds(card);
|
||||
if (card.id_evenement) {
|
||||
const absStatut =
|
||||
card.statut === CardInstanceStatutType.TRAITEE
|
||||
? null
|
||||
: card.id_evenement;
|
||||
// Supprime l’absence liée si pas encore acceptée définitivement
|
||||
// Supprime l’absence liée si pas encore acceptée définitivement (ou si soin_enfant dans les 24h)
|
||||
if (
|
||||
card.statut === CardInstanceStatutType.OUVERTE ||
|
||||
card.statut === CardInstanceStatutType.REFUSEE
|
||||
card.statut === CardInstanceStatutType.REFUSEE ||
|
||||
card.type_code === 'soin_enfant'
|
||||
) {
|
||||
await this.evenementsService.supprimer(userId, role, card.id_evenement);
|
||||
}
|
||||
@@ -379,6 +503,9 @@ export class CardsService {
|
||||
if (typeCode === 'arret_maladie_am') {
|
||||
return TypeEvenementAgendaType.ARRET_MALADIE_AM;
|
||||
}
|
||||
if (typeCode === 'soin_enfant') {
|
||||
return TypeEvenementAgendaType.SOIN_ENFANT;
|
||||
}
|
||||
throw new BadRequestException(`Type non mappé à une absence: ${typeCode}`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user