diff --git a/backend/src/routes/assistantes_maternelles/assistantes_maternelles.service.ts b/backend/src/routes/assistantes_maternelles/assistantes_maternelles.service.ts index 9949126..66a3c97 100644 --- a/backend/src/routes/assistantes_maternelles/assistantes_maternelles.service.ts +++ b/backend/src/routes/assistantes_maternelles/assistantes_maternelles.service.ts @@ -13,6 +13,7 @@ import { Children, StatutEnfantType } from 'src/entities/children.entity'; import { CreateAssistanteDto } from '../user/dto/create_assistante.dto'; import { UpdateAssistanteDto } from '../user/dto/update_assistante.dto'; import { UpdateAmFicheAdminDto } from './dto/update-am-fiche-admin.dto'; +import { validateNir } from 'src/common/utils/nir.util'; const AM_CHILDREN_RELATIONS = ['user', 'amChildren', 'amChildren.child'] as const; @@ -99,6 +100,15 @@ export class AssistantesMaternellesService { if (dto.ville !== undefined) user.ville = dto.ville; if (dto.code_postal !== undefined) user.code_postal = dto.code_postal; if (dto.statut !== undefined) user.statut = dto.statut; + if (dto.date_naissance !== undefined) { + user.date_naissance = dto.date_naissance ? new Date(dto.date_naissance) : undefined; + } + if (dto.lieu_naissance_ville !== undefined) { + user.lieu_naissance_ville = dto.lieu_naissance_ville || undefined; + } + if (dto.lieu_naissance_pays !== undefined) { + user.lieu_naissance_pays = dto.lieu_naissance_pays || undefined; + } await this.usersRepository.save(user); @@ -109,6 +119,33 @@ export class AssistantesMaternellesService { if (dto.places_available !== undefined) amPatch.places_available = dto.places_available; if (dto.biography !== undefined) amPatch.biography = dto.biography; if (dto.available !== undefined) amPatch.available = dto.available; + if (dto.agreement_date !== undefined) { + amPatch.agreement_date = dto.agreement_date ? new Date(dto.agreement_date) : undefined; + } + + if (dto.nir !== undefined) { + const nirNormalized = dto.nir.replace(/\s/g, '').toUpperCase(); + if (nirNormalized) { + const nirValidation = validateNir(nirNormalized, { + dateNaissance: + dto.date_naissance ?? user.date_naissance?.toISOString().slice(0, 10), + }); + if (!nirValidation.valid) { + throw new BadRequestException(nirValidation.error || 'NIR invalide'); + } + const nirDejaUtilise = await this.assistantesMaternelleRepository.findOne({ + where: { nir: nirNormalized }, + }); + if (nirDejaUtilise && nirDejaUtilise.user_id !== amUserId) { + throw new ConflictException( + 'Un compte assistante maternelle avec ce numéro NIR existe déjà.', + ); + } + amPatch.nir = nirNormalized; + } else { + (amPatch as { nir?: string | null }).nir = null; + } + } if (Object.keys(amPatch).length > 0) { await this.assistantesMaternelleRepository.update(amUserId, amPatch); diff --git a/backend/src/routes/assistantes_maternelles/dto/update-am-fiche-admin.dto.ts b/backend/src/routes/assistantes_maternelles/dto/update-am-fiche-admin.dto.ts index 81a665d..cbac068 100644 --- a/backend/src/routes/assistantes_maternelles/dto/update-am-fiche-admin.dto.ts +++ b/backend/src/routes/assistantes_maternelles/dto/update-am-fiche-admin.dto.ts @@ -1,6 +1,7 @@ import { ApiPropertyOptional } from '@nestjs/swagger'; import { IsBoolean, + IsDateString, IsEmail, IsEnum, IsInt, @@ -59,12 +60,40 @@ export class UpdateAmFicheAdminDto { @IsEnum(StatutUtilisateurType) statut?: StatutUtilisateurType; + @ApiPropertyOptional({ example: '123456789012345' }) + @IsOptional() + @IsString() + @MaxLength(15) + nir?: string; + + @ApiPropertyOptional({ example: '1985-03-12' }) + @IsOptional() + @IsDateString() + date_naissance?: string; + + @ApiPropertyOptional({ example: 'Lyon' }) + @IsOptional() + @IsString() + @MaxLength(100) + lieu_naissance_ville?: string; + + @ApiPropertyOptional({ example: 'France' }) + @IsOptional() + @IsString() + @MaxLength(100) + lieu_naissance_pays?: string; + @ApiPropertyOptional({ example: 'AGR-2024-12345' }) @IsOptional() @IsString() @MaxLength(50) approval_number?: string; + @ApiPropertyOptional({ example: '2020-01-15' }) + @IsOptional() + @IsDateString() + agreement_date?: string; + @ApiPropertyOptional({ example: 'Lyon' }) @IsOptional() @IsString()