feat(#131): back placement AM↔enfant + BDD garde/sans_garde
- API PATCH …/fiche, POST/DELETE …/enfants/:enfantId, GET avec amChildren - Table enfants_assistantes_maternelles (option D, 1 garde active/enfant) - Statuts enfant: garde/sans_garde remplacent actif (inscription → sans_garde) - BDD.sql canonique réécrit; migration pour BDD existantes - Seed test: hash bcrypt corrigé pour mot de passe « password » Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
CreateDateColumn,
|
||||
} from 'typeorm';
|
||||
import { AssistanteMaternelle } from './assistantes_maternelles.entity';
|
||||
import { Children } from './children.entity';
|
||||
import { Users } from './users.entity';
|
||||
|
||||
@Entity('enfants_assistantes_maternelles', { schema: 'public' })
|
||||
export class AmChildren {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ name: 'id_am', type: 'uuid' })
|
||||
amId: string;
|
||||
|
||||
@Column({ name: 'id_enfant', type: 'uuid' })
|
||||
enfantId: string;
|
||||
|
||||
@Column({ name: 'date_debut', type: 'date' })
|
||||
date_debut: Date;
|
||||
|
||||
@Column({ name: 'date_fin', type: 'date', nullable: true })
|
||||
date_fin?: Date;
|
||||
|
||||
@CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
|
||||
cree_le: Date;
|
||||
|
||||
@Column({ name: 'cree_par', type: 'uuid', nullable: true })
|
||||
cree_par?: string;
|
||||
|
||||
@ManyToOne(() => AssistanteMaternelle, (am) => am.amChildren, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'id_am', referencedColumnName: 'user_id' })
|
||||
am: AssistanteMaternelle;
|
||||
|
||||
@ManyToOne(() => Children, (c) => c.amLinks, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'id_enfant', referencedColumnName: 'id' })
|
||||
child: Children;
|
||||
|
||||
@ManyToOne(() => Users, { nullable: true, onDelete: 'SET NULL' })
|
||||
@JoinColumn({ name: 'cree_par', referencedColumnName: 'id' })
|
||||
createdBy?: Users;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Entity, PrimaryColumn, Column, OneToOne, JoinColumn } from 'typeorm';
|
||||
import { Entity, PrimaryColumn, Column, OneToOne, OneToMany, JoinColumn } from 'typeorm';
|
||||
import { Users } from './users.entity';
|
||||
import { AmChildren } from './am_children.entity';
|
||||
|
||||
@Entity('assistantes_maternelles')
|
||||
export class AssistanteMaternelle {
|
||||
@@ -51,4 +52,7 @@ export class AssistanteMaternelle {
|
||||
/** Numéro de dossier (format AAAA-NNNNNN), même valeur que sur utilisateurs (ticket #103) */
|
||||
@Column({ name: 'numero_dossier', length: 20, nullable: true })
|
||||
numero_dossier?: string;
|
||||
|
||||
@OneToMany(() => AmChildren, (ac) => ac.am)
|
||||
amChildren: AmChildren[];
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@ import {
|
||||
} from 'typeorm';
|
||||
import { Parents } from './parents.entity';
|
||||
import { ParentsChildren } from './parents_children.entity';
|
||||
import { AmChildren } from './am_children.entity';
|
||||
import { Dossier } from './dossiers.entity';
|
||||
|
||||
export enum StatutEnfantType {
|
||||
A_NAITRE = 'a_naitre',
|
||||
ACTIF = 'actif',
|
||||
SCOLARISE = 'scolarise',
|
||||
GARDE = 'garde',
|
||||
SANS_GARDE = 'sans_garde',
|
||||
}
|
||||
|
||||
export enum GenreType {
|
||||
@@ -68,6 +70,9 @@ export class Children {
|
||||
@OneToMany(() => ParentsChildren, pc => pc.child)
|
||||
parentLinks: ParentsChildren[];
|
||||
|
||||
@OneToMany(() => AmChildren, (ac) => ac.child)
|
||||
amLinks: AmChildren[];
|
||||
|
||||
// Relation avec Dossier
|
||||
@OneToMany(() => Dossier, d => d.child)
|
||||
dossiers: Dossier[];
|
||||
|
||||
@@ -12,11 +12,14 @@ import { AssistantesMaternellesService } from './assistantes_maternelles.service
|
||||
import { ApiBearerAuth, ApiBody, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
||||
import { Roles } from 'src/common/decorators/roles.decorator';
|
||||
import { RoleType } from 'src/entities/users.entity';
|
||||
import { RoleType, Users } from 'src/entities/users.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 { RolesGuard } from 'src/common/guards/roles.guard';
|
||||
import { AuthGuard } from 'src/common/guards/auth.guard';
|
||||
import { User } from 'src/common/decorators/user.decorator';
|
||||
import { mapAmForApi, mapAmsForApi } from './assistantes_maternelles.mapper';
|
||||
|
||||
@ApiTags("Assistantes Maternelles")
|
||||
@ApiBearerAuth('access-token')
|
||||
@@ -31,28 +34,74 @@ export class AssistantesMaternellesController {
|
||||
@ApiResponse({ status: 403, description: 'Accès refusé : Réservé aux super_admins et gestionnaires' })
|
||||
@ApiBody({ type: CreateAssistanteDto })
|
||||
@Post()
|
||||
create(@Body() dto: CreateAssistanteDto): Promise<AssistanteMaternelle> {
|
||||
return this.assistantesMaternellesService.create(dto);
|
||||
async create(@Body() dto: CreateAssistanteDto): Promise<AssistanteMaternelle> {
|
||||
const am = await this.assistantesMaternellesService.create(dto);
|
||||
return mapAmForApi(am);
|
||||
}
|
||||
|
||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE, RoleType.ADMINISTRATEUR)
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'Récupérer la liste des nounous' })
|
||||
@ApiOperation({ summary: 'Récupérer la liste des nounous (inclut amChildren actifs) — ticket #131' })
|
||||
@ApiResponse({ status: 200, description: 'Liste des nounous' })
|
||||
@ApiResponse({ status: 403, description: 'Accès refusé : Réservé aux super_admins et gestionnaires' })
|
||||
getAll(): Promise<AssistanteMaternelle[]> {
|
||||
return this.assistantesMaternellesService.findAll();
|
||||
async getAll(): Promise<AssistanteMaternelle[]> {
|
||||
const ams = await this.assistantesMaternellesService.findAll();
|
||||
return mapAmsForApi(ams);
|
||||
}
|
||||
|
||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE, RoleType.ADMINISTRATEUR)
|
||||
@Get(':id')
|
||||
@ApiParam({ name: 'id', description: "UUID de la nounou" })
|
||||
@ApiOperation({ summary: 'Récupérer une nounou par id' })
|
||||
@ApiOperation({ summary: 'Récupérer une nounou par id (inclut amChildren) — ticket #131' })
|
||||
@ApiResponse({ status: 200, description: 'Détails de la nounou' })
|
||||
@ApiResponse({ status: 404, description: 'Nounou non trouvée' })
|
||||
@ApiResponse({ status: 403, description: 'Accès refusé : Réservé aux super_admins et gestionnaires' })
|
||||
getOne(@Param('id') user_id: string): Promise<AssistanteMaternelle> {
|
||||
return this.assistantesMaternellesService.findOne(user_id);
|
||||
@ApiResponse({ status: 403, description: 'Accès refusé' })
|
||||
async getOne(@Param('id') user_id: string): Promise<AssistanteMaternelle> {
|
||||
const am = await this.assistantesMaternellesService.findOne(user_id);
|
||||
return mapAmForApi(am);
|
||||
}
|
||||
|
||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE, RoleType.ADMINISTRATEUR)
|
||||
@Patch(':id/fiche')
|
||||
@ApiBody({ type: UpdateAmFicheAdminDto })
|
||||
@ApiOperation({ summary: 'Mettre à jour la fiche AM (identité + pro) — ticket #131' })
|
||||
@ApiParam({ name: 'id', description: "UUID utilisateur de l'AM" })
|
||||
@ApiResponse({ status: 200, description: 'Fiche AM mise à jour' })
|
||||
async updateFicheAdmin(
|
||||
@Param('id') id: string,
|
||||
@Body() dto: UpdateAmFicheAdminDto,
|
||||
): Promise<AssistanteMaternelle> {
|
||||
const am = await this.assistantesMaternellesService.updateFicheAdmin(id, dto);
|
||||
return mapAmForApi(am);
|
||||
}
|
||||
|
||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE, RoleType.ADMINISTRATEUR)
|
||||
@Post(':id/enfants/:enfantId')
|
||||
@ApiOperation({ summary: 'Rattacher un enfant à une AM (statut enfant → garde) — ticket #131' })
|
||||
@ApiParam({ name: 'id', description: "UUID utilisateur de l'AM" })
|
||||
@ApiParam({ name: 'enfantId', description: "UUID de l'enfant" })
|
||||
@ApiResponse({ status: 200, description: 'AM avec enfants mis à jour' })
|
||||
async attachEnfant(
|
||||
@Param('id') id: string,
|
||||
@Param('enfantId') enfantId: string,
|
||||
@User() currentUser: Users,
|
||||
): Promise<AssistanteMaternelle> {
|
||||
const am = await this.assistantesMaternellesService.attachEnfant(id, enfantId, currentUser);
|
||||
return mapAmForApi(am);
|
||||
}
|
||||
|
||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE, RoleType.ADMINISTRATEUR)
|
||||
@Delete(':id/enfants/:enfantId')
|
||||
@ApiOperation({ summary: "Clôturer le placement d'un enfant chez une AM — ticket #131" })
|
||||
@ApiParam({ name: 'id', description: "UUID utilisateur de l'AM" })
|
||||
@ApiParam({ name: 'enfantId', description: "UUID de l'enfant" })
|
||||
@ApiResponse({ status: 200, description: 'AM avec enfants mis à jour' })
|
||||
async detachEnfant(
|
||||
@Param('id') id: string,
|
||||
@Param('enfantId') enfantId: string,
|
||||
): Promise<AssistanteMaternelle> {
|
||||
const am = await this.assistantesMaternellesService.detachEnfant(id, enfantId);
|
||||
return mapAmForApi(am);
|
||||
}
|
||||
|
||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
||||
@@ -63,14 +112,15 @@ export class AssistantesMaternellesController {
|
||||
@ApiResponse({ status: 404, description: 'Nounou non trouvée' })
|
||||
@ApiParam({ name: 'id', description: "UUID de la nounou" })
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() dto: UpdateAssistanteDto): Promise<AssistanteMaternelle> {
|
||||
return this.assistantesMaternellesService.update(id, dto);
|
||||
async update(@Param('id') id: string, @Body() dto: UpdateAssistanteDto): Promise<AssistanteMaternelle> {
|
||||
const am = await this.assistantesMaternellesService.update(id, dto);
|
||||
return mapAmForApi(am);
|
||||
}
|
||||
|
||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE, RoleType.ADMINISTRATEUR)
|
||||
@ApiOperation({ summary: 'Supprimer une nounou' })
|
||||
@ApiResponse({ status: 200, description: 'Nounou supprimée avec succès' })
|
||||
@ApiResponse({ status: 403, description: 'Accès refusé : Réservé aux super_admins, gestionnaires et administrateurs' })
|
||||
@ApiResponse({ status: 403, description: 'Accès refusé' })
|
||||
@ApiResponse({ status: 404, description: 'Nounou non trouvée' })
|
||||
@ApiParam({ name: 'id', description: "UUID de la nounou" })
|
||||
@Delete(':id')
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
||||
import { AmChildren } from 'src/entities/am_children.entity';
|
||||
import { sanitizeUserForApi } from '../../common/utils/sanitize-user-for-api';
|
||||
|
||||
/**
|
||||
* Sérialisation API fiche AM — ticket #131.
|
||||
* Expose `amChildren` actifs (date_fin null) avec enfant imbriqué, sans secrets user.
|
||||
*/
|
||||
export function mapAmForApi(am: AssistanteMaternelle): AssistanteMaternelle {
|
||||
const activeChildren = (am.amChildren ?? []).filter((link) => !link.date_fin);
|
||||
|
||||
return {
|
||||
...am,
|
||||
user: sanitizeUserForApi(am.user)!,
|
||||
amChildren: activeChildren.map((link) => ({
|
||||
...link,
|
||||
child: link.child,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
export function mapAmsForApi(ams: AssistanteMaternelle[]): AssistanteMaternelle[] {
|
||||
return ams.map(mapAmForApi);
|
||||
}
|
||||
|
||||
export function filterActiveAmChildren(links: AmChildren[] | undefined): AmChildren[] {
|
||||
return (links ?? []).filter((link) => !link.date_fin);
|
||||
}
|
||||
@@ -2,12 +2,14 @@ import { Module } from '@nestjs/common';
|
||||
import { AssistantesMaternellesService } from './assistantes_maternelles.service';
|
||||
import { AssistantesMaternellesController } from './assistantes_maternelles.controller';
|
||||
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
||||
import { AmChildren } from 'src/entities/am_children.entity';
|
||||
import { Children } from 'src/entities/children.entity';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Users } from 'src/entities/users.entity';
|
||||
import { AuthModule } from '../auth/auth.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([AssistanteMaternelle, Users]),
|
||||
imports: [TypeOrmModule.forFeature([AssistanteMaternelle, AmChildren, Children, Users]),
|
||||
AuthModule
|
||||
],
|
||||
controllers: [AssistantesMaternellesController],
|
||||
|
||||
@@ -5,11 +5,16 @@ import {
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { IsNull, Repository } from 'typeorm';
|
||||
import { RoleType, Users } from 'src/entities/users.entity';
|
||||
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
||||
import { AmChildren } from 'src/entities/am_children.entity';
|
||||
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';
|
||||
|
||||
const AM_CHILDREN_RELATIONS = ['user', 'amChildren', 'amChildren.child'] as const;
|
||||
|
||||
@Injectable()
|
||||
export class AssistantesMaternellesService {
|
||||
@@ -17,10 +22,13 @@ export class AssistantesMaternellesService {
|
||||
@InjectRepository(AssistanteMaternelle)
|
||||
private readonly assistantesMaternelleRepository: Repository<AssistanteMaternelle>,
|
||||
@InjectRepository(Users)
|
||||
private readonly usersRepository: Repository<Users>
|
||||
private readonly usersRepository: Repository<Users>,
|
||||
@InjectRepository(AmChildren)
|
||||
private readonly amChildrenRepository: Repository<AmChildren>,
|
||||
@InjectRepository(Children)
|
||||
private readonly childrenRepository: Repository<Children>,
|
||||
) {}
|
||||
|
||||
// Création d’une assistante maternelle
|
||||
async create(dto: CreateAssistanteDto): Promise<AssistanteMaternelle> {
|
||||
const user = await this.usersRepository.findOneBy({ id: dto.user_id });
|
||||
if (!user) throw new NotFoundException('Utilisateur introuvable');
|
||||
@@ -49,30 +57,167 @@ export class AssistantesMaternellesService {
|
||||
return this.assistantesMaternelleRepository.save(entity);
|
||||
}
|
||||
|
||||
// Liste des assistantes maternelles
|
||||
async findAll(): Promise<AssistanteMaternelle[]> {
|
||||
return this.assistantesMaternelleRepository.find({
|
||||
relations: ['user'],
|
||||
relations: [...AM_CHILDREN_RELATIONS],
|
||||
});
|
||||
}
|
||||
|
||||
// Récupérer une assistante maternelle par user_id
|
||||
async findOne(user_id: string): Promise<AssistanteMaternelle> {
|
||||
const assistante = await this.assistantesMaternelleRepository.findOne({
|
||||
where: { user_id },
|
||||
relations: ['user'],
|
||||
relations: [...AM_CHILDREN_RELATIONS],
|
||||
});
|
||||
if (!assistante) throw new NotFoundException('Assistante maternelle introuvable');
|
||||
return assistante;
|
||||
}
|
||||
|
||||
// Mise à jour
|
||||
async update(id: string, dto: UpdateAssistanteDto): Promise<AssistanteMaternelle> {
|
||||
await this.assistantesMaternelleRepository.update(id, dto);
|
||||
return this.findOne(id);
|
||||
}
|
||||
|
||||
// Suppression d’une assistante maternelle
|
||||
/**
|
||||
* Mise à jour fiche AM (identité + champs pro) par admin/gestionnaire. Ticket #131.
|
||||
*/
|
||||
async updateFicheAdmin(amUserId: string, dto: UpdateAmFicheAdminDto): Promise<AssistanteMaternelle> {
|
||||
const am = await this.findOne(amUserId);
|
||||
const user = am.user;
|
||||
|
||||
if (dto.email && dto.email !== user.email) {
|
||||
const existing = await this.usersRepository.findOne({ where: { email: dto.email } });
|
||||
if (existing && existing.id !== user.id) {
|
||||
throw new ConflictException('Cet email est déjà utilisé');
|
||||
}
|
||||
user.email = dto.email;
|
||||
}
|
||||
|
||||
if (dto.nom !== undefined) user.nom = dto.nom;
|
||||
if (dto.prenom !== undefined) user.prenom = dto.prenom;
|
||||
if (dto.telephone !== undefined) user.telephone = dto.telephone;
|
||||
if (dto.adresse !== undefined) user.adresse = dto.adresse;
|
||||
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;
|
||||
|
||||
await this.usersRepository.save(user);
|
||||
|
||||
const amPatch: Partial<AssistanteMaternelle> = {};
|
||||
if (dto.approval_number !== undefined) amPatch.approval_number = dto.approval_number;
|
||||
if (dto.residence_city !== undefined) amPatch.residence_city = dto.residence_city;
|
||||
if (dto.max_children !== undefined) amPatch.max_children = dto.max_children;
|
||||
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 (Object.keys(amPatch).length > 0) {
|
||||
await this.assistantesMaternelleRepository.update(amUserId, amPatch);
|
||||
}
|
||||
|
||||
return this.findOne(amUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rattacher un enfant à une AM (placement actif). Ticket #131.
|
||||
* Passe le statut enfant à `garde` (sauf a_naitre / scolarise).
|
||||
*/
|
||||
async attachEnfant(amUserId: string, enfantId: string, createdBy?: Users): Promise<AssistanteMaternelle> {
|
||||
const am = await this.findOne(amUserId);
|
||||
|
||||
const existingForAm = await this.amChildrenRepository.findOne({
|
||||
where: { amId: amUserId, enfantId, date_fin: IsNull() },
|
||||
});
|
||||
if (existingForAm) {
|
||||
throw new ConflictException('Cet enfant est déjà rattaché à cette assistante maternelle');
|
||||
}
|
||||
|
||||
const child = await this.childrenRepository.findOne({ where: { id: enfantId } });
|
||||
if (!child) {
|
||||
throw new NotFoundException('Enfant introuvable');
|
||||
}
|
||||
|
||||
const activeForChild = await this.amChildrenRepository.findOne({
|
||||
where: { enfantId, date_fin: IsNull() },
|
||||
});
|
||||
if (activeForChild && activeForChild.amId !== amUserId) {
|
||||
throw new ConflictException(
|
||||
'Cet enfant est déjà en garde chez une autre assistante maternelle',
|
||||
);
|
||||
}
|
||||
|
||||
const activeCount = await this.amChildrenRepository.count({
|
||||
where: { amId: amUserId, date_fin: IsNull() },
|
||||
});
|
||||
if (am.max_children != null && activeCount >= am.max_children) {
|
||||
throw new BadRequestException(
|
||||
`Capacité maximale atteinte (${am.max_children} enfant(s))`,
|
||||
);
|
||||
}
|
||||
|
||||
await this.amChildrenRepository.save(
|
||||
this.amChildrenRepository.create({
|
||||
amId: amUserId,
|
||||
enfantId,
|
||||
date_debut: new Date(),
|
||||
cree_par: createdBy?.id,
|
||||
}),
|
||||
);
|
||||
|
||||
await this.applyGardeStatusOnAttach(child);
|
||||
|
||||
return this.findOne(amUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clôturer le placement AM ↔ enfant. Ticket #131.
|
||||
* Repasse l'enfant en `sans_garde` s'il n'a plus de placement actif.
|
||||
*/
|
||||
async detachEnfant(amUserId: string, enfantId: string): Promise<AssistanteMaternelle> {
|
||||
await this.findOne(amUserId);
|
||||
|
||||
const link = await this.amChildrenRepository.findOne({
|
||||
where: { amId: amUserId, enfantId, date_fin: IsNull() },
|
||||
relations: ['child'],
|
||||
});
|
||||
if (!link) {
|
||||
throw new NotFoundException('Lien assistante maternelle-enfant introuvable');
|
||||
}
|
||||
|
||||
link.date_fin = new Date();
|
||||
await this.amChildrenRepository.save(link);
|
||||
|
||||
const remaining = await this.amChildrenRepository.count({
|
||||
where: { enfantId, date_fin: IsNull() },
|
||||
});
|
||||
if (remaining === 0 && link.child) {
|
||||
await this.applySansGardeStatusOnDetach(link.child);
|
||||
}
|
||||
|
||||
return this.findOne(amUserId);
|
||||
}
|
||||
|
||||
private async applyGardeStatusOnAttach(child: Children): Promise<void> {
|
||||
if (
|
||||
child.status === StatutEnfantType.A_NAITRE ||
|
||||
child.status === StatutEnfantType.SCOLARISE
|
||||
) {
|
||||
return;
|
||||
}
|
||||
child.status = StatutEnfantType.GARDE;
|
||||
await this.childrenRepository.save(child);
|
||||
}
|
||||
|
||||
private async applySansGardeStatusOnDetach(child: Children): Promise<void> {
|
||||
if (
|
||||
child.status === StatutEnfantType.A_NAITRE ||
|
||||
child.status === StatutEnfantType.SCOLARISE
|
||||
) {
|
||||
return;
|
||||
}
|
||||
child.status = StatutEnfantType.SANS_GARDE;
|
||||
await this.childrenRepository.save(child);
|
||||
}
|
||||
|
||||
async remove(id: string): Promise<{ message: string }> {
|
||||
await this.assistantesMaternelleRepository.delete(id);
|
||||
return { message: 'Assistante maternelle supprimée' };
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import {
|
||||
IsBoolean,
|
||||
IsEmail,
|
||||
IsEnum,
|
||||
IsInt,
|
||||
IsOptional,
|
||||
IsString,
|
||||
Max,
|
||||
MaxLength,
|
||||
Min,
|
||||
} from 'class-validator';
|
||||
import { StatutUtilisateurType } from 'src/entities/users.entity';
|
||||
|
||||
/** Mise à jour fiche AM par admin/gestionnaire (doc 28 §6.1, ticket #131). */
|
||||
export class UpdateAmFicheAdminDto {
|
||||
@ApiPropertyOptional({ example: 'MARTIN' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(100)
|
||||
nom?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: 'Claire' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(100)
|
||||
prenom?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: 'claire@example.com' })
|
||||
@IsOptional()
|
||||
@IsEmail()
|
||||
email?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: '0612345678' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(20)
|
||||
telephone?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: '5 place Bellecour' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
adresse?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: 'Lyon' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(150)
|
||||
ville?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: '69002' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(10)
|
||||
code_postal?: string;
|
||||
|
||||
@ApiPropertyOptional({ enum: StatutUtilisateurType })
|
||||
@IsOptional()
|
||||
@IsEnum(StatutUtilisateurType)
|
||||
statut?: StatutUtilisateurType;
|
||||
|
||||
@ApiPropertyOptional({ example: 'AGR-2024-12345' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(50)
|
||||
approval_number?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: 'Lyon' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(100)
|
||||
residence_city?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: 4 })
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
@Max(10)
|
||||
max_children?: number;
|
||||
|
||||
@ApiPropertyOptional({ example: 2 })
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
@Max(10)
|
||||
places_available?: number;
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
biography?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: true })
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
available?: boolean;
|
||||
}
|
||||
@@ -176,7 +176,7 @@ describe('AuthService (#118 create-password API)', () => {
|
||||
parentsServiceMock.getDossierFamilleByNumero.mockResolvedValue({
|
||||
numero_dossier: '2026-000021',
|
||||
parents: [{ user_id: 'p1', email: 'claire@test.fr', statut: StatutUtilisateurType.REFUSE }],
|
||||
enfants: [{ id: 'e1', first_name: 'Emma', status: 'actif' }],
|
||||
enfants: [{ id: 'e1', first_name: 'Emma', status: 'sans_garde' }],
|
||||
texte_motivation: 'Motivation test',
|
||||
});
|
||||
|
||||
|
||||
@@ -551,7 +551,7 @@ export class AuthService {
|
||||
? new Date(enfantDto.date_previsionnelle_naissance)
|
||||
: undefined;
|
||||
enfant.photo_url = urlPhoto || undefined;
|
||||
enfant.status = enfantDto.date_naissance ? StatutEnfantType.ACTIF : StatutEnfantType.A_NAITRE;
|
||||
enfant.status = enfantDto.date_naissance ? StatutEnfantType.SANS_GARDE : StatutEnfantType.A_NAITRE;
|
||||
enfant.consent_photo = false;
|
||||
enfant.is_multiple = enfantDto.grossesse_multiple || false;
|
||||
|
||||
@@ -1063,7 +1063,7 @@ export class AuthService {
|
||||
if (enfantDto.genre !== undefined) enfant.gender = enfantDto.genre;
|
||||
if (enfantDto.date_naissance !== undefined) {
|
||||
enfant.birth_date = new Date(enfantDto.date_naissance);
|
||||
enfant.status = StatutEnfantType.ACTIF;
|
||||
enfant.status = StatutEnfantType.SANS_GARDE;
|
||||
}
|
||||
if (enfantDto.date_previsionnelle_naissance !== undefined) {
|
||||
enfant.due_date = new Date(enfantDto.date_previsionnelle_naissance);
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
import { GenreType, StatutEnfantType } from 'src/entities/children.entity';
|
||||
|
||||
export class CreateEnfantsDto {
|
||||
@ApiProperty({ enum: StatutEnfantType, example: StatutEnfantType.ACTIF })
|
||||
@ApiProperty({ enum: StatutEnfantType, example: StatutEnfantType.SANS_GARDE })
|
||||
@IsEnum(StatutEnfantType)
|
||||
@IsNotEmpty()
|
||||
status: StatutEnfantType;
|
||||
|
||||
@@ -34,7 +34,7 @@ export class EnfantsService {
|
||||
|
||||
// Vérif métier simple
|
||||
if (dto.status !== StatutEnfantType.A_NAITRE && !dto.birth_date) {
|
||||
throw new BadRequestException('Un enfant actif doit avoir une date de naissance');
|
||||
throw new BadRequestException('Un enfant né doit avoir une date de naissance');
|
||||
}
|
||||
|
||||
// Vérif doublon éventuel (ex: même prénom + date de naissance pour ce parent)
|
||||
|
||||
Reference in New Issue
Block a user