fix(#131): aligner PATCH fiche AM back sur le payload front
Étend UpdateAmFicheAdminDto (nir, date/lieu naissance, agreement_date) et persiste ces champs dans updateFicheAdmin avec validation NIR. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
18718670e9
commit
9ad371a342
@ -13,6 +13,7 @@ import { Children, StatutEnfantType } from 'src/entities/children.entity';
|
|||||||
import { CreateAssistanteDto } from '../user/dto/create_assistante.dto';
|
import { CreateAssistanteDto } from '../user/dto/create_assistante.dto';
|
||||||
import { UpdateAssistanteDto } from '../user/dto/update_assistante.dto';
|
import { UpdateAssistanteDto } from '../user/dto/update_assistante.dto';
|
||||||
import { UpdateAmFicheAdminDto } from './dto/update-am-fiche-admin.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;
|
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.ville !== undefined) user.ville = dto.ville;
|
||||||
if (dto.code_postal !== undefined) user.code_postal = dto.code_postal;
|
if (dto.code_postal !== undefined) user.code_postal = dto.code_postal;
|
||||||
if (dto.statut !== undefined) user.statut = dto.statut;
|
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);
|
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.places_available !== undefined) amPatch.places_available = dto.places_available;
|
||||||
if (dto.biography !== undefined) amPatch.biography = dto.biography;
|
if (dto.biography !== undefined) amPatch.biography = dto.biography;
|
||||||
if (dto.available !== undefined) amPatch.available = dto.available;
|
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) {
|
if (Object.keys(amPatch).length > 0) {
|
||||||
await this.assistantesMaternelleRepository.update(amUserId, amPatch);
|
await this.assistantesMaternelleRepository.update(amUserId, amPatch);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
import {
|
import {
|
||||||
IsBoolean,
|
IsBoolean,
|
||||||
|
IsDateString,
|
||||||
IsEmail,
|
IsEmail,
|
||||||
IsEnum,
|
IsEnum,
|
||||||
IsInt,
|
IsInt,
|
||||||
@ -59,12 +60,40 @@ export class UpdateAmFicheAdminDto {
|
|||||||
@IsEnum(StatutUtilisateurType)
|
@IsEnum(StatutUtilisateurType)
|
||||||
statut?: 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' })
|
@ApiPropertyOptional({ example: 'AGR-2024-12345' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
@MaxLength(50)
|
@MaxLength(50)
|
||||||
approval_number?: string;
|
approval_number?: string;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ example: '2020-01-15' })
|
||||||
|
@IsOptional()
|
||||||
|
@IsDateString()
|
||||||
|
agreement_date?: string;
|
||||||
|
|
||||||
@ApiPropertyOptional({ example: 'Lyon' })
|
@ApiPropertyOptional({ example: 'Lyon' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user