feat: pending-families ajoute parents[] (email/tel/ville/cp) + ordre stable
Made-with: Cursor
This commit is contained in:
@@ -94,6 +94,7 @@ export class ParentsService {
|
||||
date_soumission: Date | string | null;
|
||||
nombre_enfants: string | number | null;
|
||||
emails: unknown;
|
||||
parents: unknown;
|
||||
}[];
|
||||
try {
|
||||
raw = await this.parentsRepository.query(`
|
||||
@@ -121,7 +122,7 @@ export class ParentsService {
|
||||
)
|
||||
SELECT
|
||||
'Famille ' || string_agg(u.nom, ' - ' ORDER BY u.nom, u.prenom) AS libelle,
|
||||
array_agg(DISTINCT p.id_utilisateur ORDER BY p.id_utilisateur) AS "parentIds",
|
||||
array_agg(p.id_utilisateur ORDER BY u.nom, u.prenom, u.id) AS "parentIds",
|
||||
(array_agg(p.numero_dossier))[1] AS numero_dossier,
|
||||
MIN(u.cree_le) AS date_soumission,
|
||||
COALESCE((
|
||||
@@ -131,7 +132,17 @@ export class ParentsService {
|
||||
SELECT frx.id FROM family_rep frx WHERE frx.rep = fr.rep
|
||||
)
|
||||
), 0) AS nombre_enfants,
|
||||
array_agg(u.email ORDER BY u.nom, u.prenom) AS emails
|
||||
array_agg(u.email ORDER BY u.nom, u.prenom, u.id) AS emails,
|
||||
json_agg(
|
||||
json_build_object(
|
||||
'id', u.id::text,
|
||||
'email', u.email,
|
||||
'telephone', u.telephone,
|
||||
'code_postal', u.code_postal,
|
||||
'ville', u.ville
|
||||
)
|
||||
ORDER BY u.nom, u.prenom, u.id
|
||||
) AS parents
|
||||
FROM family_rep fr
|
||||
JOIN parents p ON p.id_utilisateur = fr.id
|
||||
JOIN utilisateurs u ON u.id = p.id_utilisateur
|
||||
@@ -150,6 +161,7 @@ export class ParentsService {
|
||||
date_soumission: this.toIsoDateTimeOrNull(r.date_soumission),
|
||||
nombre_enfants: this.normalizeNombreEnfants(r.nombre_enfants),
|
||||
emails: this.normalizeEmails(r.emails),
|
||||
parents: this.normalizeParents(r.parents),
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -175,6 +187,27 @@ export class ParentsService {
|
||||
return [];
|
||||
}
|
||||
|
||||
private normalizeParents(parents: unknown): { id: string; email: string; telephone: string | null; code_postal: string | null; ville: string | null }[] {
|
||||
if (Array.isArray(parents)) {
|
||||
return parents.map((p: any) => ({
|
||||
id: String(p?.id ?? ''),
|
||||
email: String(p?.email ?? ''),
|
||||
telephone: p?.telephone != null ? String(p.telephone) : null,
|
||||
code_postal: p?.code_postal != null ? String(p.code_postal) : null,
|
||||
ville: p?.ville != null ? String(p.ville) : null,
|
||||
}));
|
||||
}
|
||||
if (typeof parents === 'string') {
|
||||
try {
|
||||
const parsed = JSON.parse(parents);
|
||||
return this.normalizeParents(parsed);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/** Convertit parentIds (array ou chaîne PG) en string[] pour éviter 500 si le driver renvoie une chaîne. */
|
||||
private normalizeParentIds(parentIds: unknown): string[] {
|
||||
if (Array.isArray(parentIds)) return parentIds.map(String);
|
||||
|
||||
Reference in New Issue
Block a user