[Backend] API Inscription Parent - REFONTE Workflow 6 etapes (#72)

Co-authored-by: Julien Martin <julien.martin@ptits-pas.fr>
Co-committed-by: Julien Martin <julien.martin@ptits-pas.fr>
This commit was merged in pull request #72.
This commit is contained in:
2025-12-01 21:43:36 +00:00
committed by jmartin
parent 9aea26805d
commit 579b6cae90
10 changed files with 861 additions and 14 deletions
+21 -3
View File
@@ -24,10 +24,11 @@ export class EnfantsService {
private readonly parentsChildrenRepository: Repository<ParentsChildren>,
) { }
// Création dun enfant
async create(dto: CreateEnfantsDto, currentUser: Users): Promise<Children> {
// Création d'un enfant
async create(dto: CreateEnfantsDto, currentUser: Users, photoFile?: Express.Multer.File): Promise<Children> {
const parent = await this.parentsRepository.findOne({
where: { user_id: currentUser.id },
relations: ['co_parent'],
});
if (!parent) throw new NotFoundException('Parent introuvable');
@@ -46,17 +47,34 @@ export class EnfantsService {
});
if (exist) throw new ConflictException('Cet enfant existe déjà');
// Gestion de la photo uploadée
if (photoFile) {
dto.photo_url = `/uploads/photos/${photoFile.filename}`;
if (dto.consent_photo) {
dto.consent_photo_at = new Date().toISOString();
}
}
// Création
const child = this.childrenRepository.create(dto);
await this.childrenRepository.save(child);
// Lien parent-enfant
// Lien parent-enfant (Parent 1)
const parentLink = this.parentsChildrenRepository.create({
parentId: parent.user_id,
enfantId: child.id,
});
await this.parentsChildrenRepository.save(parentLink);
// Rattachement automatique au co-parent s'il existe
if (parent.co_parent) {
const coParentLink = this.parentsChildrenRepository.create({
parentId: parent.co_parent.id,
enfantId: child.id,
});
await this.parentsChildrenRepository.save(coParentLink);
}
return this.findOne(child.id, currentUser);
}