feat(#119): dossier famille = 1 par famille, N enfants; retrait repas/type_contrat/budget; adresse dans API parents
Made-with: Cursor
This commit is contained in:
@@ -15,6 +15,12 @@ export class DossierFamilleParentDto {
|
||||
nom?: string;
|
||||
@ApiProperty({ required: false })
|
||||
telephone?: string;
|
||||
@ApiProperty({ required: false })
|
||||
adresse?: string;
|
||||
@ApiProperty({ required: false })
|
||||
ville?: string;
|
||||
@ApiProperty({ required: false })
|
||||
code_postal?: string;
|
||||
@ApiProperty({ enum: StatutUtilisateurType })
|
||||
statut: StatutUtilisateurType;
|
||||
@ApiProperty({ required: false, description: 'Id du co-parent si couple' })
|
||||
@@ -39,7 +45,7 @@ export class DossierFamilleEnfantDto {
|
||||
status: StatutEnfantType;
|
||||
}
|
||||
|
||||
/** Dossier (parent+enfant) avec presentation */
|
||||
/** Dossier (parent+enfant) avec presentation – inscription famille, pas dossier de garde */
|
||||
export class DossierFamillePresentationDto {
|
||||
@ApiProperty()
|
||||
id: string;
|
||||
@@ -47,14 +53,8 @@ export class DossierFamillePresentationDto {
|
||||
id_parent: string;
|
||||
@ApiProperty()
|
||||
id_enfant: string;
|
||||
@ApiProperty({ required: false, description: 'Texte de présentation' })
|
||||
@ApiProperty({ required: false, description: 'Texte de motivation' })
|
||||
presentation?: string;
|
||||
@ApiProperty({ required: false })
|
||||
type_contrat?: string;
|
||||
@ApiProperty()
|
||||
repas: boolean;
|
||||
@ApiProperty({ required: false })
|
||||
budget?: number;
|
||||
@ApiProperty({ enum: StatutDossierType })
|
||||
statut: StatutDossierType;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { Parents } from 'src/entities/parents.entity';
|
||||
import { DossierFamille, DossierFamilleEnfant } from 'src/entities/dossier_famille.entity';
|
||||
import { ParentsController } from './parents.controller';
|
||||
import { ParentsService } from './parents.service';
|
||||
import { Users } from 'src/entities/users.entity';
|
||||
@@ -10,7 +11,7 @@ import { UserModule } from '../user/user.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Parents, Users]),
|
||||
TypeOrmModule.forFeature([Parents, Users, DossierFamille, DossierFamilleEnfant]),
|
||||
forwardRef(() => UserModule),
|
||||
JwtModule.registerAsync({
|
||||
imports: [ConfigModule],
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { In, Repository } from 'typeorm';
|
||||
import { Parents } from 'src/entities/parents.entity';
|
||||
import { DossierFamille } from 'src/entities/dossier_famille.entity';
|
||||
import { RoleType, Users } from 'src/entities/users.entity';
|
||||
import { CreateParentDto } from '../user/dto/create_parent.dto';
|
||||
import { UpdateParentsDto } from '../user/dto/update_parent.dto';
|
||||
@@ -25,6 +26,8 @@ export class ParentsService {
|
||||
private readonly parentsRepository: Repository<Parents>,
|
||||
@InjectRepository(Users)
|
||||
private readonly usersRepository: Repository<Users>,
|
||||
@InjectRepository(DossierFamille)
|
||||
private readonly dossierFamilleRepository: Repository<DossierFamille>,
|
||||
) {}
|
||||
|
||||
// Création d’un parent
|
||||
@@ -165,7 +168,29 @@ export class ParentsService {
|
||||
relations: ['user', 'co_parent', 'parentChildren', 'parentChildren.child', 'dossiers', 'dossiers.child'],
|
||||
});
|
||||
const enfantsMap = new Map<string, DossierFamilleEnfantDto>();
|
||||
const presentationList: DossierFamillePresentationDto[] = [];
|
||||
let presentationList: DossierFamillePresentationDto[] = [];
|
||||
|
||||
// Un dossier = une famille : priorité à dossier_famille (un texte, N enfants)
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const p of parents) {
|
||||
// Enfants via parentChildren
|
||||
if (p.parentChildren) {
|
||||
@@ -183,17 +208,14 @@ export class ParentsService {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Dossiers (présentation)
|
||||
if (p.dossiers) {
|
||||
// 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,
|
||||
type_contrat: d.type_contrat,
|
||||
repas: d.meals,
|
||||
budget: d.budget != null ? Number(d.budget) : undefined,
|
||||
statut: d.status,
|
||||
});
|
||||
}
|
||||
@@ -205,6 +227,9 @@ export class ParentsService {
|
||||
prenom: p.user.prenom,
|
||||
nom: p.user.nom,
|
||||
telephone: p.user.telephone,
|
||||
adresse: p.user.adresse,
|
||||
ville: p.user.ville,
|
||||
code_postal: p.user.code_postal,
|
||||
statut: p.user.statut,
|
||||
co_parent_id: p.co_parent?.id,
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user