fix(cards): resolve typescript errors with payload typing
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -137,7 +137,7 @@ export class CardsService {
|
|||||||
const absenceType = this.mapAbsenceType(dto.type_code);
|
const absenceType = this.mapAbsenceType(dto.type_code);
|
||||||
|
|
||||||
let motif = dto.motif ?? null;
|
let motif = dto.motif ?? null;
|
||||||
let finalPayload = {
|
let finalPayload: Record<string, any> = {
|
||||||
date_debut: dto.date_debut,
|
date_debut: dto.date_debut,
|
||||||
date_fin: dto.date_fin,
|
date_fin: dto.date_fin,
|
||||||
motif,
|
motif,
|
||||||
@@ -145,40 +145,40 @@ export class CardsService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (dto.type_code === 'soin_enfant') {
|
if (dto.type_code === 'soin_enfant') {
|
||||||
const p = dto.payload;
|
const p = dto.payload as Record<string, any>;
|
||||||
if (!p || !p.sous_type || !p.heure_releve) {
|
if (!p || !p?.sous_type || !p?.heure_releve) {
|
||||||
throw new BadRequestException('sous_type et heure_releve requis pour soin_enfant');
|
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)) {
|
if (!/^([01]\d|2[0-3]):([0-5]\d)$/.test(p?.heure_releve)) {
|
||||||
throw new BadRequestException('Format heure_releve invalide (HH:mm)');
|
throw new BadRequestException('Format heure_releve invalide (HH:mm)');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.sous_type === 'fievre') {
|
if (p?.sous_type === 'fievre') {
|
||||||
if (typeof p.temperature_c !== 'number' || p.temperature_c < 34.0 || p.temperature_c > 43.0) {
|
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)');
|
throw new BadRequestException('temperature_c invalide (34.0 - 43.0)');
|
||||||
}
|
}
|
||||||
motif = `${p.temperature_c.toFixed(1).replace('.', ',')} °C à ${p.heure_releve}`;
|
motif = `${p?.temperature_c.toFixed(1).replace('.', ',')} °C à ${p?.heure_releve}`;
|
||||||
if (p.medicament_donne && typeof p.medicament_donne === 'string' && p.medicament_donne.trim()) {
|
if (p?.medicament_donne && typeof p?.medicament_donne === 'string' && p?.medicament_donne.trim()) {
|
||||||
motif += ` (Médicament : ${p.medicament_donne.trim()})`;
|
motif += ` (Médicament : ${p?.medicament_donne.trim()})`;
|
||||||
}
|
}
|
||||||
} else if (p.sous_type === 'bobo') {
|
} else if (p?.sous_type === 'bobo') {
|
||||||
const natures = ['chute', 'coup', 'egratignure', 'piqure', 'brulure', 'autre'];
|
const natures = ['chute', 'coup', 'egratignure', 'piqure', 'brulure', 'autre'];
|
||||||
if (!natures.includes(p.bobo_nature)) {
|
if (!natures.includes(p?.bobo_nature)) {
|
||||||
throw new BadRequestException('bobo_nature invalide');
|
throw new BadRequestException('bobo_nature invalide');
|
||||||
}
|
}
|
||||||
motif = `Bobo (${p.bobo_nature}) à ${p.heure_releve}`;
|
motif = `Bobo (${p?.bobo_nature}) à ${p?.heure_releve}`;
|
||||||
if (p.description && typeof p.description === 'string' && p.description.trim()) {
|
if (p?.description && typeof p?.description === 'string' && p?.description.trim()) {
|
||||||
const desc = p.description.trim();
|
const desc = p?.description.trim();
|
||||||
if (desc.length > 120) throw new BadRequestException('description trop longue (max 120)');
|
if (desc.length > 120) throw new BadRequestException('description trop longue (max 120)');
|
||||||
motif += ` : ${desc.length > 30 ? desc.substring(0, 30) + '...' : desc}`;
|
motif += ` : ${desc.length > 30 ? desc.substring(0, 30) + '...' : desc}`;
|
||||||
}
|
}
|
||||||
} else if (p.sous_type === 'medicament') {
|
} else if (p?.sous_type === 'medicament') {
|
||||||
if (!p.medicament_nom || typeof p.medicament_nom !== 'string' || !p.medicament_nom.trim()) {
|
if (!p?.medicament_nom || typeof p?.medicament_nom !== 'string' || !p?.medicament_nom.trim()) {
|
||||||
throw new BadRequestException('medicament_nom requis');
|
throw new BadRequestException('medicament_nom requis');
|
||||||
}
|
}
|
||||||
motif = `Médicament (${p.medicament_nom.trim()}) à ${p.heure_releve}`;
|
motif = `Médicament (${p?.medicament_nom.trim()}) à ${p?.heure_releve}`;
|
||||||
if (p.contexte && typeof p.contexte === 'string' && p.contexte.trim()) {
|
if (p?.contexte && typeof p?.contexte === 'string' && p?.contexte.trim()) {
|
||||||
if (p.contexte.trim().length > 120) throw new BadRequestException('contexte trop long (max 120)');
|
if (p?.contexte.trim().length > 120) throw new BadRequestException('contexte trop long (max 120)');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new BadRequestException('sous_type invalide pour soin_enfant');
|
throw new BadRequestException('sous_type invalide pour soin_enfant');
|
||||||
@@ -192,7 +192,7 @@ export class CardsService {
|
|||||||
type: absenceType,
|
type: absenceType,
|
||||||
date_debut: dto.date_debut,
|
date_debut: dto.date_debut,
|
||||||
date_fin: dto.date_fin,
|
date_fin: dto.date_fin,
|
||||||
motif: motif ?? undefined,
|
motif: motif ? String(motif) : undefined,
|
||||||
});
|
});
|
||||||
absenceId = absence.id;
|
absenceId = absence.id;
|
||||||
} else {
|
} else {
|
||||||
@@ -205,7 +205,7 @@ export class CardsService {
|
|||||||
await this.evenementsService.maj(userId, role, absenceId, {
|
await this.evenementsService.maj(userId, role, absenceId, {
|
||||||
date_debut: dto.date_debut,
|
date_debut: dto.date_debut,
|
||||||
date_fin: dto.date_fin,
|
date_fin: dto.date_fin,
|
||||||
motif: motif ?? undefined,
|
motif: motif ? String(motif) : undefined,
|
||||||
// Congé accepté modifié → repasse en attente via cartes respond flow;
|
// Congé accepté modifié → repasse en attente via cartes respond flow;
|
||||||
// pour absence enfant update immédiat déjà fait.
|
// pour absence enfant update immédiat déjà fait.
|
||||||
...(dto.type_code === 'conge_am'
|
...(dto.type_code === 'conge_am'
|
||||||
@@ -352,7 +352,7 @@ export class CardsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let motif = dto.motif ?? card.payload?.['motif'] ?? null;
|
let motif = dto.motif ?? card.payload?.['motif'] ?? null;
|
||||||
let finalPayload = {
|
let finalPayload: Record<string, any> = {
|
||||||
...card.payload,
|
...card.payload,
|
||||||
date_debut: debut,
|
date_debut: debut,
|
||||||
date_fin: fin,
|
date_fin: fin,
|
||||||
@@ -361,39 +361,39 @@ export class CardsService {
|
|||||||
|
|
||||||
if (card.type_code === 'soin_enfant') {
|
if (card.type_code === 'soin_enfant') {
|
||||||
const p = finalPayload;
|
const p = finalPayload;
|
||||||
if (!p || !p.sous_type || !p.heure_releve) {
|
if (!p || !p?.sous_type || !p?.heure_releve) {
|
||||||
throw new BadRequestException('sous_type et heure_releve requis pour soin_enfant');
|
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)) {
|
if (!/^([01]\d|2[0-3]):([0-5]\d)$/.test(p?.heure_releve)) {
|
||||||
throw new BadRequestException('Format heure_releve invalide (HH:mm)');
|
throw new BadRequestException('Format heure_releve invalide (HH:mm)');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.sous_type === 'fievre') {
|
if (p?.sous_type === 'fievre') {
|
||||||
if (typeof p.temperature_c !== 'number' || p.temperature_c < 34.0 || p.temperature_c > 43.0) {
|
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)');
|
throw new BadRequestException('temperature_c invalide (34.0 - 43.0)');
|
||||||
}
|
}
|
||||||
motif = `${p.temperature_c.toFixed(1).replace('.', ',')} °C à ${p.heure_releve}`;
|
motif = `${p?.temperature_c.toFixed(1).replace('.', ',')} °C à ${p?.heure_releve}`;
|
||||||
if (p.medicament_donne && typeof p.medicament_donne === 'string' && p.medicament_donne.trim()) {
|
if (p?.medicament_donne && typeof p?.medicament_donne === 'string' && p?.medicament_donne.trim()) {
|
||||||
motif += ` (Médicament : ${p.medicament_donne.trim()})`;
|
motif += ` (Médicament : ${p?.medicament_donne.trim()})`;
|
||||||
}
|
}
|
||||||
} else if (p.sous_type === 'bobo') {
|
} else if (p?.sous_type === 'bobo') {
|
||||||
const natures = ['chute', 'coup', 'egratignure', 'piqure', 'brulure', 'autre'];
|
const natures = ['chute', 'coup', 'egratignure', 'piqure', 'brulure', 'autre'];
|
||||||
if (!natures.includes(p.bobo_nature)) {
|
if (!natures.includes(p?.bobo_nature)) {
|
||||||
throw new BadRequestException('bobo_nature invalide');
|
throw new BadRequestException('bobo_nature invalide');
|
||||||
}
|
}
|
||||||
motif = `Bobo (${p.bobo_nature}) à ${p.heure_releve}`;
|
motif = `Bobo (${p?.bobo_nature}) à ${p?.heure_releve}`;
|
||||||
if (p.description && typeof p.description === 'string' && p.description.trim()) {
|
if (p?.description && typeof p?.description === 'string' && p?.description.trim()) {
|
||||||
const desc = p.description.trim();
|
const desc = p?.description.trim();
|
||||||
if (desc.length > 120) throw new BadRequestException('description trop longue (max 120)');
|
if (desc.length > 120) throw new BadRequestException('description trop longue (max 120)');
|
||||||
motif += ` : ${desc.length > 30 ? desc.substring(0, 30) + '...' : desc}`;
|
motif += ` : ${desc.length > 30 ? desc.substring(0, 30) + '...' : desc}`;
|
||||||
}
|
}
|
||||||
} else if (p.sous_type === 'medicament') {
|
} else if (p?.sous_type === 'medicament') {
|
||||||
if (!p.medicament_nom || typeof p.medicament_nom !== 'string' || !p.medicament_nom.trim()) {
|
if (!p?.medicament_nom || typeof p?.medicament_nom !== 'string' || !p?.medicament_nom.trim()) {
|
||||||
throw new BadRequestException('medicament_nom requis');
|
throw new BadRequestException('medicament_nom requis');
|
||||||
}
|
}
|
||||||
motif = `Médicament (${p.medicament_nom.trim()}) à ${p.heure_releve}`;
|
motif = `Médicament (${p?.medicament_nom.trim()}) à ${p?.heure_releve}`;
|
||||||
if (p.contexte && typeof p.contexte === 'string' && p.contexte.trim()) {
|
if (p?.contexte && typeof p?.contexte === 'string' && p?.contexte.trim()) {
|
||||||
if (p.contexte.trim().length > 120) throw new BadRequestException('contexte trop long (max 120)');
|
if (p?.contexte.trim().length > 120) throw new BadRequestException('contexte trop long (max 120)');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new BadRequestException('sous_type invalide pour soin_enfant');
|
throw new BadRequestException('sous_type invalide pour soin_enfant');
|
||||||
@@ -418,7 +418,7 @@ export class CardsService {
|
|||||||
await this.evenementsService.maj(userId, role, card.id_evenement, {
|
await this.evenementsService.maj(userId, role, card.id_evenement, {
|
||||||
date_debut: debut,
|
date_debut: debut,
|
||||||
date_fin: fin,
|
date_fin: fin,
|
||||||
motif: motif ?? undefined,
|
motif: motif ? String(motif) : undefined,
|
||||||
...(card.type_code !== 'soin_enfant' ? { statut: StatutEvenementAgendaType.EN_ATTENTE } : {}),
|
...(card.type_code !== 'soin_enfant' ? { statut: StatutEvenementAgendaType.EN_ATTENTE } : {}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user