diff --git a/backend/src/routes/parents/dto/dossier-famille-complet.dto.ts b/backend/src/routes/parents/dto/dossier-famille-complet.dto.ts index 29437cf..d051b0d 100644 --- a/backend/src/routes/parents/dto/dossier-famille-complet.dto.ts +++ b/backend/src/routes/parents/dto/dossier-famille-complet.dto.ts @@ -42,6 +42,18 @@ export class DossierFamilleEnfantDto { due_date?: Date; @ApiProperty({ enum: StatutEnfantType }) status: StatutEnfantType; + + @ApiProperty({ + required: false, + description: 'Chemin ou URL de la photo (souvent relatif, ex. /uploads/photos/...)', + }) + photo_url?: string; + + @ApiProperty({ + required: false, + description: 'Consentement affichage photo (colonne consentement_photo)', + }) + consent_photo?: boolean; } /** Réponse GET /parents/dossier-famille/:numeroDossier – dossier famille complet. Ticket #119 */ diff --git a/backend/src/routes/parents/parents.service.ts b/backend/src/routes/parents/parents.service.ts index f4d6f53..ae9bedd 100644 --- a/backend/src/routes/parents/parents.service.ts +++ b/backend/src/routes/parents/parents.service.ts @@ -17,6 +17,7 @@ import { DossierFamilleParentDto, DossierFamilleEnfantDto, } from './dto/dossier-famille-complet.dto'; +import { Children } from 'src/entities/children.entity'; @Injectable() export class ParentsService { @@ -209,6 +210,20 @@ export class ParentsService { } /** Convertit parentIds (array ou chaîne PG) en string[] pour éviter 500 si le driver renvoie une chaîne. */ + private childToDossierFamilleEnfantDto(child: Children): DossierFamilleEnfantDto { + return { + id: child.id, + first_name: child.first_name, + last_name: child.last_name, + genre: child.gender, + birth_date: child.birth_date, + due_date: child.due_date, + status: child.status, + photo_url: child.photo_url ?? undefined, + consent_photo: child.consent_photo, + }; + } + private normalizeParentIds(parentIds: unknown): string[] { if (Array.isArray(parentIds)) return parentIds.map(String); if (typeof parentIds === 'string') { @@ -257,15 +272,7 @@ export class ParentsService { if (p.parentChildren) { for (const pc of p.parentChildren) { if (pc.child && !enfantsMap.has(pc.child.id)) { - enfantsMap.set(pc.child.id, { - id: pc.child.id, - first_name: pc.child.first_name, - last_name: pc.child.last_name, - genre: pc.child.gender, - birth_date: pc.child.birth_date, - due_date: pc.child.due_date, - status: pc.child.status, - }); + enfantsMap.set(pc.child.id, this.childToDossierFamilleEnfantDto(pc.child)); } } } @@ -275,6 +282,16 @@ export class ParentsService { } } + // Enfants uniquement liés via dossier_famille_enfants (legacy / parcours alternatif) + if (dossierFamille?.enfants?.length) { + for (const dfe of dossierFamille.enfants) { + const c = dfe.enfant; + if (c && !enfantsMap.has(c.id)) { + enfantsMap.set(c.id, this.childToDossierFamilleEnfantDto(c)); + } + } + } + const parentsDto: DossierFamilleParentDto[] = parents.map((p) => ({ user_id: p.user_id, email: p.user.email,