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 778a589..29437cf 100644 --- a/backend/src/routes/parents/dto/dossier-famille-complet.dto.ts +++ b/backend/src/routes/parents/dto/dossier-famille-complet.dto.ts @@ -1,6 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; import { StatutUtilisateurType } from 'src/entities/users.entity'; -import { StatutDossierType } from 'src/entities/dossiers.entity'; import { StatutEnfantType, GenreType } from 'src/entities/children.entity'; /** Parent dans le dossier famille (infos utilisateur + parent) */ @@ -45,20 +44,6 @@ export class DossierFamilleEnfantDto { status: StatutEnfantType; } -/** Dossier (parent+enfant) avec presentation – inscription famille, pas dossier de garde */ -export class DossierFamillePresentationDto { - @ApiProperty() - id: string; - @ApiProperty() - id_parent: string; - @ApiProperty() - id_enfant: string; - @ApiProperty({ required: false, description: 'Texte de motivation' }) - presentation?: string; - @ApiProperty({ enum: StatutDossierType }) - statut: StatutDossierType; -} - /** Réponse GET /parents/dossier-famille/:numeroDossier – dossier famille complet. Ticket #119 */ export class DossierFamilleCompletDto { @ApiProperty({ example: '2026-000001', description: 'Numéro de dossier famille' }) @@ -67,6 +52,6 @@ export class DossierFamilleCompletDto { parents: DossierFamilleParentDto[]; @ApiProperty({ type: [DossierFamilleEnfantDto], description: 'Enfants de la famille' }) enfants: DossierFamilleEnfantDto[]; - @ApiProperty({ type: [DossierFamillePresentationDto], description: 'Dossiers (présentation par parent/enfant)' }) - presentation: DossierFamillePresentationDto[]; + @ApiProperty({ required: false, description: 'Texte de présentation / motivation (un seul par famille)' }) + texte_motivation?: string; } diff --git a/backend/src/routes/parents/parents.service.ts b/backend/src/routes/parents/parents.service.ts index d151d4d..54db406 100644 --- a/backend/src/routes/parents/parents.service.ts +++ b/backend/src/routes/parents/parents.service.ts @@ -16,7 +16,6 @@ import { DossierFamilleCompletDto, DossierFamilleParentDto, DossierFamilleEnfantDto, - DossierFamillePresentationDto, } from './dto/dossier-famille-complet.dto'; @Injectable() @@ -168,27 +167,15 @@ export class ParentsService { relations: ['user', 'co_parent', 'parentChildren', 'parentChildren.child', 'dossiers', 'dossiers.child'], }); const enfantsMap = new Map(); - let presentationList: DossierFamillePresentationDto[] = []; + let texte_motivation: string | undefined; - // Un dossier = une famille : priorité à dossier_famille (un texte, N enfants) + // Un dossier = une famille, un seul texte de motivation const dossierFamille = await this.dossierFamilleRepository.findOne({ where: { numero_dossier: num }, relations: ['parent', 'enfants', 'enfants.enfant'], }); - if (dossierFamille?.enfants?.length) { - const idParent = dossierFamille.parent?.user_id ?? familyUserIds[0]; - for (const dfe of dossierFamille.enfants) { - const idEnfant = dfe.enfant?.id ?? dfe.id_enfant; - if (idEnfant) { - presentationList.push({ - id: dossierFamille.id, - id_parent: idParent, - id_enfant: idEnfant, - presentation: dossierFamille.presentation, - statut: dossierFamille.statut, - }); - } - } + if (dossierFamille?.presentation) { + texte_motivation = dossierFamille.presentation; } for (const p of parents) { @@ -208,19 +195,12 @@ export class ParentsService { } } } - // Si pas de dossier_famille : fallback sur anciens dossiers (parent+enfant) - if (presentationList.length === 0 && p.dossiers) { - for (const d of p.dossiers) { - presentationList.push({ - id: d.id, - id_parent: p.user_id, - id_enfant: d.child?.id ?? '', - presentation: d.presentation, - statut: d.status, - }); - } + // Fallback : anciens dossiers (un texte, on prend le premier) + if (texte_motivation == null && p.dossiers?.length) { + texte_motivation = p.dossiers[0].presentation ?? undefined; } } + const parentsDto: DossierFamilleParentDto[] = parents.map((p) => ({ user_id: p.user_id, email: p.user.email, @@ -237,7 +217,7 @@ export class ParentsService { numero_dossier: num, parents: parentsDto, enfants: Array.from(enfantsMap.values()), - presentation: presentationList, + texte_motivation, }; }