Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b1b9e7917 |
@@ -16,7 +16,7 @@ import { AllExceptionsFilter } from './common/filters/all_exceptions.filters';
|
|||||||
import { EnfantsModule } from './routes/enfants/enfants.module';
|
import { EnfantsModule } from './routes/enfants/enfants.module';
|
||||||
import { AppConfigModule } from './modules/config/config.module';
|
import { AppConfigModule } from './modules/config/config.module';
|
||||||
import { DocumentsLegauxModule } from './modules/documents-legaux';
|
import { DocumentsLegauxModule } from './modules/documents-legaux';
|
||||||
import { EvenementsAgendaModule } from './modules/evenements-agenda';
|
import { AbsencesGardeModule } from './modules/absences-garde';
|
||||||
import { CardsModule } from './modules/cards';
|
import { CardsModule } from './modules/cards';
|
||||||
import { RelaisModule } from './routes/relais/relais.module';
|
import { RelaisModule } from './routes/relais/relais.module';
|
||||||
import { DossiersModule } from './routes/dossiers/dossiers.module';
|
import { DossiersModule } from './routes/dossiers/dossiers.module';
|
||||||
@@ -58,7 +58,7 @@ import { SuppressionsModule } from './routes/suppressions/suppressions.module';
|
|||||||
AuthModule,
|
AuthModule,
|
||||||
AppConfigModule,
|
AppConfigModule,
|
||||||
DocumentsLegauxModule,
|
DocumentsLegauxModule,
|
||||||
EvenementsAgendaModule,
|
AbsencesGardeModule,
|
||||||
CardsModule,
|
CardsModule,
|
||||||
RelaisModule,
|
RelaisModule,
|
||||||
DossiersModule,
|
DossiersModule,
|
||||||
|
|||||||
+14
-14
@@ -10,25 +10,25 @@ import {
|
|||||||
import { AmChildren } from './am_children.entity';
|
import { AmChildren } from './am_children.entity';
|
||||||
import { Users } from './users.entity';
|
import { Users } from './users.entity';
|
||||||
|
|
||||||
export enum TypeEvenementAgendaType {
|
export enum TypeAbsenceGardeType {
|
||||||
ABSENCE_ENFANT = 'absence_enfant',
|
ABSENCE_ENFANT = 'absence_enfant',
|
||||||
CONGE_AM = 'conge_am',
|
CONGE_AM = 'conge_am',
|
||||||
ARRET_MALADIE_AM = 'arret_maladie_am',
|
ARRET_MALADIE_AM = 'arret_maladie_am',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum StatutEvenementAgendaType {
|
export enum StatutAbsenceGardeType {
|
||||||
EN_ATTENTE = 'en_attente',
|
EN_ATTENTE = 'en_attente',
|
||||||
ACCEPTE = 'accepte',
|
ACCEPTE = 'accepte',
|
||||||
REFUSE = 'refuse',
|
REFUSE = 'refuse',
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vérité métier agenda par couple AM↔enfant (placement).
|
* Vérité métier des absences / congés / arrêts par couple AM↔enfant.
|
||||||
* Types V1 : absences / congés / arrêts ; extensible (soins, école, mairie…).
|
* Les cartes (module ultérieur) collectent ; cette table stocke.
|
||||||
* Les cartes collectent ; cette table historise. Ticket #205.
|
* Ticket #193.
|
||||||
*/
|
*/
|
||||||
@Entity('evenements_agenda', { schema: 'public' })
|
@Entity('absences_garde', { schema: 'public' })
|
||||||
export class EvenementsAgenda {
|
export class AbsencesGarde {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
@@ -41,11 +41,11 @@ export class EvenementsAgenda {
|
|||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
type: 'enum',
|
type: 'enum',
|
||||||
enum: TypeEvenementAgendaType,
|
enum: TypeAbsenceGardeType,
|
||||||
enumName: 'type_evenement_agenda_type',
|
enumName: 'type_absence_garde_type',
|
||||||
name: 'type',
|
name: 'type',
|
||||||
})
|
})
|
||||||
type: TypeEvenementAgendaType;
|
type: TypeAbsenceGardeType;
|
||||||
|
|
||||||
@Column({ name: 'date_debut', type: 'date' })
|
@Column({ name: 'date_debut', type: 'date' })
|
||||||
date_debut: string;
|
date_debut: string;
|
||||||
@@ -55,12 +55,12 @@ export class EvenementsAgenda {
|
|||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
type: 'enum',
|
type: 'enum',
|
||||||
enum: StatutEvenementAgendaType,
|
enum: StatutAbsenceGardeType,
|
||||||
enumName: 'statut_evenement_agenda_type',
|
enumName: 'statut_absence_garde_type',
|
||||||
name: 'statut',
|
name: 'statut',
|
||||||
default: StatutEvenementAgendaType.EN_ATTENTE,
|
default: StatutAbsenceGardeType.EN_ATTENTE,
|
||||||
})
|
})
|
||||||
statut: StatutEvenementAgendaType;
|
statut: StatutAbsenceGardeType;
|
||||||
|
|
||||||
/** Purge auto pour en_attente/refuse ; accepte → infinity. */
|
/** Purge auto pour en_attente/refuse ; accepte → infinity. */
|
||||||
@Column({ name: 'expire_at', type: 'timestamptz' })
|
@Column({ name: 'expire_at', type: 'timestamptz' })
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Entity, PrimaryColumn, Column, OneToOne, OneToMany, JoinColumn, ManyToOne } from 'typeorm';
|
import { Entity, PrimaryColumn, Column, OneToOne, OneToMany, JoinColumn } from 'typeorm';
|
||||||
import { Users } from './users.entity';
|
import { Users } from './users.entity';
|
||||||
import { AmChildren } from './am_children.entity';
|
import { AmChildren } from './am_children.entity';
|
||||||
|
|
||||||
@@ -37,32 +37,22 @@ export class AssistanteMaternelle {
|
|||||||
@Column({ name: 'ville_residence', length: 100, nullable: true })
|
@Column({ name: 'ville_residence', length: 100, nullable: true })
|
||||||
residence_city?: string;
|
residence_city?: string;
|
||||||
|
|
||||||
@Column({ name: 'date_agrement', type: 'date', nullable: true })
|
@Column( { name: 'date_agrement', type: 'date', nullable: true })
|
||||||
agreement_date?: Date;
|
agreement_date?: Date;
|
||||||
|
|
||||||
@Column({ name: 'annee_experience', type: 'smallint', nullable: true })
|
@Column( { name: 'annee_experience', type: 'smallint', nullable: true })
|
||||||
years_experience?: number;
|
years_experience?: number;
|
||||||
|
|
||||||
@Column({ name: 'specialite', length: 100, nullable: true })
|
@Column( { name: 'specialite', length: 100, nullable: true })
|
||||||
specialty?: string;
|
specialty?: string;
|
||||||
|
|
||||||
@Column({ name: 'place_disponible', type: 'integer', nullable: true })
|
@Column( { name: 'place_disponible', type: 'integer', nullable: true })
|
||||||
places_available?: number;
|
places_available?: number;
|
||||||
|
|
||||||
/** Numéro de dossier (format AAAA-NNNNNN), même valeur que sur utilisateurs (ticket #103) */
|
/** Numéro de dossier (format AAAA-NNNNNN), même valeur que sur utilisateurs (ticket #103) */
|
||||||
@Column({ name: 'numero_dossier', length: 20, nullable: true })
|
@Column({ name: 'numero_dossier', length: 20, nullable: true })
|
||||||
numero_dossier?: string;
|
numero_dossier?: string;
|
||||||
|
|
||||||
/**
|
|
||||||
* Placement AM↔enfant sélectionné sur le TdB AM (couple actif) — ticket #171.
|
|
||||||
*/
|
|
||||||
@Column({ name: 'id_placement_garde_courant', type: 'uuid', nullable: true })
|
|
||||||
id_placement_garde_courant?: string;
|
|
||||||
|
|
||||||
@ManyToOne(() => AmChildren, { nullable: true, onDelete: 'SET NULL' })
|
|
||||||
@JoinColumn({ name: 'id_placement_garde_courant', referencedColumnName: 'id' })
|
|
||||||
placement_garde_courant?: AmChildren;
|
|
||||||
|
|
||||||
@OneToMany(() => AmChildren, (ac) => ac.am)
|
@OneToMany(() => AmChildren, (ac) => ac.am)
|
||||||
amChildren: AmChildren[];
|
amChildren: AmChildren[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
UpdateDateColumn,
|
UpdateDateColumn,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
import { AmChildren } from './am_children.entity';
|
import { AmChildren } from './am_children.entity';
|
||||||
import { EvenementsAgenda } from './evenements_agenda.entity';
|
import { AbsencesGarde } from './absences_garde.entity';
|
||||||
import { Users } from './users.entity';
|
import { Users } from './users.entity';
|
||||||
import { CardType } from './card_types.entity';
|
import { CardType } from './card_types.entity';
|
||||||
import { CardAudienceMember } from './card_audience_members.entity';
|
import { CardAudienceMember } from './card_audience_members.entity';
|
||||||
@@ -45,12 +45,12 @@ export class CardInstance {
|
|||||||
@JoinColumn({ name: 'id_placement', referencedColumnName: 'id' })
|
@JoinColumn({ name: 'id_placement', referencedColumnName: 'id' })
|
||||||
placement: AmChildren;
|
placement: AmChildren;
|
||||||
|
|
||||||
@Column({ name: 'id_evenement', type: 'uuid', nullable: true })
|
@Column({ name: 'id_absence', type: 'uuid', nullable: true })
|
||||||
id_evenement?: string;
|
id_absence?: string;
|
||||||
|
|
||||||
@ManyToOne(() => EvenementsAgenda, { nullable: true, onDelete: 'SET NULL' })
|
@ManyToOne(() => AbsencesGarde, { nullable: true, onDelete: 'SET NULL' })
|
||||||
@JoinColumn({ name: 'id_evenement', referencedColumnName: 'id' })
|
@JoinColumn({ name: 'id_absence', referencedColumnName: 'id' })
|
||||||
evenement?: EvenementsAgenda;
|
absence?: AbsencesGarde;
|
||||||
|
|
||||||
@Column({ name: 'cree_par', type: 'uuid', nullable: true })
|
@Column({ name: 'cree_par', type: 'uuid', nullable: true })
|
||||||
cree_par?: string;
|
cree_par?: string;
|
||||||
|
|||||||
+9
-9
@@ -1,13 +1,13 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { EvenementsAgendaController } from './evenements-agenda.controller';
|
import { AbsencesGardeController } from './absences-garde.controller';
|
||||||
import { EvenementsAgendaService } from './evenements-agenda.service';
|
import { AbsencesGardeService } from './absences-garde.service';
|
||||||
import { AuthGuard } from 'src/common/guards/auth.guard';
|
import { AuthGuard } from 'src/common/guards/auth.guard';
|
||||||
import { RolesGuard } from 'src/common/guards/roles.guard';
|
import { RolesGuard } from 'src/common/guards/roles.guard';
|
||||||
import { RoleType } from 'src/entities/users.entity';
|
import { RoleType } from 'src/entities/users.entity';
|
||||||
import { TypeEvenementAgendaType } from 'src/entities/evenements_agenda.entity';
|
import { TypeAbsenceGardeType } from 'src/entities/absences_garde.entity';
|
||||||
|
|
||||||
describe('EvenementsAgendaController (#172)', () => {
|
describe('AbsencesGardeController (#172)', () => {
|
||||||
let controller: EvenementsAgendaController;
|
let controller: AbsencesGardeController;
|
||||||
const serviceMock = {
|
const serviceMock = {
|
||||||
lister: jest.fn(),
|
lister: jest.fn(),
|
||||||
creer: jest.fn(),
|
creer: jest.fn(),
|
||||||
@@ -17,8 +17,8 @@ describe('EvenementsAgendaController (#172)', () => {
|
|||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
controllers: [EvenementsAgendaController],
|
controllers: [AbsencesGardeController],
|
||||||
providers: [{ provide: EvenementsAgendaService, useValue: serviceMock }],
|
providers: [{ provide: AbsencesGardeService, useValue: serviceMock }],
|
||||||
})
|
})
|
||||||
.overrideGuard(AuthGuard)
|
.overrideGuard(AuthGuard)
|
||||||
.useValue({ canActivate: () => true })
|
.useValue({ canActivate: () => true })
|
||||||
@@ -26,7 +26,7 @@ describe('EvenementsAgendaController (#172)', () => {
|
|||||||
.useValue({ canActivate: () => true })
|
.useValue({ canActivate: () => true })
|
||||||
.compile();
|
.compile();
|
||||||
|
|
||||||
controller = module.get(EvenementsAgendaController);
|
controller = module.get(AbsencesGardeController);
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ describe('EvenementsAgendaController (#172)', () => {
|
|||||||
serviceMock.creer.mockResolvedValue({ id: 'a1' });
|
serviceMock.creer.mockResolvedValue({ id: 'a1' });
|
||||||
const dto = {
|
const dto = {
|
||||||
id_placement: 'pl-1',
|
id_placement: 'pl-1',
|
||||||
type: TypeEvenementAgendaType.ABSENCE_ENFANT,
|
type: TypeAbsenceGardeType.ABSENCE_ENFANT,
|
||||||
date_debut: '2026-10-01',
|
date_debut: '2026-10-01',
|
||||||
date_fin: '2026-10-02',
|
date_fin: '2026-10-02',
|
||||||
};
|
};
|
||||||
+32
-32
@@ -25,49 +25,49 @@ import { RolesGuard } from 'src/common/guards/roles.guard';
|
|||||||
import { Roles } from 'src/common/decorators/roles.decorator';
|
import { Roles } from 'src/common/decorators/roles.decorator';
|
||||||
import { User } from 'src/common/decorators/user.decorator';
|
import { User } from 'src/common/decorators/user.decorator';
|
||||||
import {
|
import {
|
||||||
StatutEvenementAgendaType,
|
StatutAbsenceGardeType,
|
||||||
TypeEvenementAgendaType,
|
TypeAbsenceGardeType,
|
||||||
} from 'src/entities/evenements_agenda.entity';
|
} from 'src/entities/absences_garde.entity';
|
||||||
import { RoleType } from 'src/entities/users.entity';
|
import { RoleType } from 'src/entities/users.entity';
|
||||||
import { EvenementsAgendaService } from './evenements-agenda.service';
|
import { AbsencesGardeService } from './absences-garde.service';
|
||||||
import {
|
import {
|
||||||
EvenementAgendaDto,
|
AbsenceGardeDto,
|
||||||
CreerEvenementAgendaDto,
|
CreerAbsenceGardeDto,
|
||||||
ListeEvenementsAgendaDto,
|
ListeAbsencesGardeDto,
|
||||||
MajEvenementAgendaDto,
|
MajAbsenceGardeDto,
|
||||||
} from './dto/evenements-agenda.dto';
|
} from './dto/absences-garde.dto';
|
||||||
|
|
||||||
@ApiTags('Événements agenda')
|
@ApiTags('Absences garde')
|
||||||
@ApiBearerAuth('access-token')
|
@ApiBearerAuth('access-token')
|
||||||
@Controller('evenements-agenda')
|
@Controller('absences-garde')
|
||||||
@UseGuards(AuthGuard, RolesGuard)
|
@UseGuards(AuthGuard, RolesGuard)
|
||||||
export class EvenementsAgendaController {
|
export class AbsencesGardeController {
|
||||||
constructor(private readonly evenementsAgendaService: EvenementsAgendaService) {}
|
constructor(private readonly absencesGardeService: AbsencesGardeService) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE)
|
@Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE)
|
||||||
@ApiOperation({
|
@ApiOperation({
|
||||||
summary: 'Lister les absences / congés / arrêts — ticket #205 / ex-#172',
|
summary: 'Lister les absences / congés / arrêts — ticket #172',
|
||||||
description:
|
description:
|
||||||
'Sans placementId : tous les placements du user (parent = famille multi-AM ; AM = tous accueils). ' +
|
'Sans placementId : tous les placements du user (parent = famille multi-AM ; AM = tous accueils). ' +
|
||||||
'Avec placementId : un couple enfant–AM.',
|
'Avec placementId : un couple enfant–AM.',
|
||||||
})
|
})
|
||||||
@ApiQuery({ name: 'placementId', required: false })
|
@ApiQuery({ name: 'placementId', required: false })
|
||||||
@ApiQuery({ name: 'type', required: false, enum: TypeEvenementAgendaType })
|
@ApiQuery({ name: 'type', required: false, enum: TypeAbsenceGardeType })
|
||||||
@ApiQuery({ name: 'statut', required: false, enum: StatutEvenementAgendaType })
|
@ApiQuery({ name: 'statut', required: false, enum: StatutAbsenceGardeType })
|
||||||
@ApiQuery({ name: 'from', required: false, description: 'YYYY-MM-DD' })
|
@ApiQuery({ name: 'from', required: false, description: 'YYYY-MM-DD' })
|
||||||
@ApiQuery({ name: 'to', required: false, description: 'YYYY-MM-DD' })
|
@ApiQuery({ name: 'to', required: false, description: 'YYYY-MM-DD' })
|
||||||
@ApiResponse({ status: 200, type: ListeEvenementsAgendaDto })
|
@ApiResponse({ status: 200, type: ListeAbsencesGardeDto })
|
||||||
lister(
|
lister(
|
||||||
@User('id') userId: string,
|
@User('id') userId: string,
|
||||||
@User('role') role: RoleType,
|
@User('role') role: RoleType,
|
||||||
@Query('placementId') placementId?: string,
|
@Query('placementId') placementId?: string,
|
||||||
@Query('type') type?: TypeEvenementAgendaType,
|
@Query('type') type?: TypeAbsenceGardeType,
|
||||||
@Query('statut') statut?: StatutEvenementAgendaType,
|
@Query('statut') statut?: StatutAbsenceGardeType,
|
||||||
@Query('from') from?: string,
|
@Query('from') from?: string,
|
||||||
@Query('to') to?: string,
|
@Query('to') to?: string,
|
||||||
): Promise<ListeEvenementsAgendaDto> {
|
): Promise<ListeAbsencesGardeDto> {
|
||||||
return this.evenementsAgendaService.lister(userId, role, {
|
return this.absencesGardeService.lister(userId, role, {
|
||||||
placementId,
|
placementId,
|
||||||
type,
|
type,
|
||||||
statut,
|
statut,
|
||||||
@@ -79,15 +79,15 @@ export class EvenementsAgendaController {
|
|||||||
@Post()
|
@Post()
|
||||||
@Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE)
|
@Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE)
|
||||||
@ApiOperation({ summary: 'Créer une période d’absence / congé / arrêt — #172' })
|
@ApiOperation({ summary: 'Créer une période d’absence / congé / arrêt — #172' })
|
||||||
@ApiBody({ type: CreerEvenementAgendaDto })
|
@ApiBody({ type: CreerAbsenceGardeDto })
|
||||||
@ApiResponse({ status: 201, type: EvenementAgendaDto })
|
@ApiResponse({ status: 201, type: AbsenceGardeDto })
|
||||||
@HttpCode(HttpStatus.CREATED)
|
@HttpCode(HttpStatus.CREATED)
|
||||||
creer(
|
creer(
|
||||||
@User('id') userId: string,
|
@User('id') userId: string,
|
||||||
@User('role') role: RoleType,
|
@User('role') role: RoleType,
|
||||||
@Body() dto: CreerEvenementAgendaDto,
|
@Body() dto: CreerAbsenceGardeDto,
|
||||||
): Promise<EvenementAgendaDto> {
|
): Promise<AbsenceGardeDto> {
|
||||||
return this.evenementsAgendaService.creer(userId, role, dto);
|
return this.absencesGardeService.creer(userId, role, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
@@ -98,15 +98,15 @@ export class EvenementsAgendaController {
|
|||||||
'Parent : accept/refuse congé (motivation si refus), ack arrêt. ' +
|
'Parent : accept/refuse congé (motivation si refus), ack arrêt. ' +
|
||||||
'AM : modifier dates (en attente / refuse / accepté), republication après refus.',
|
'AM : modifier dates (en attente / refuse / accepté), republication après refus.',
|
||||||
})
|
})
|
||||||
@ApiBody({ type: MajEvenementAgendaDto })
|
@ApiBody({ type: MajAbsenceGardeDto })
|
||||||
@ApiResponse({ status: 200, type: EvenementAgendaDto })
|
@ApiResponse({ status: 200, type: AbsenceGardeDto })
|
||||||
maj(
|
maj(
|
||||||
@User('id') userId: string,
|
@User('id') userId: string,
|
||||||
@User('role') role: RoleType,
|
@User('role') role: RoleType,
|
||||||
@Param('id', ParseUUIDPipe) id: string,
|
@Param('id', ParseUUIDPipe) id: string,
|
||||||
@Body() dto: MajEvenementAgendaDto,
|
@Body() dto: MajAbsenceGardeDto,
|
||||||
): Promise<EvenementAgendaDto> {
|
): Promise<AbsenceGardeDto> {
|
||||||
return this.evenementsAgendaService.maj(userId, role, id, dto);
|
return this.absencesGardeService.maj(userId, role, id, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
@@ -119,6 +119,6 @@ export class EvenementsAgendaController {
|
|||||||
@User('role') role: RoleType,
|
@User('role') role: RoleType,
|
||||||
@Param('id', ParseUUIDPipe) id: string,
|
@Param('id', ParseUUIDPipe) id: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await this.evenementsAgendaService.supprimer(userId, role, id);
|
await this.absencesGardeService.supprimer(userId, role, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+8
-8
@@ -2,15 +2,15 @@ import { Module } from '@nestjs/common';
|
|||||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||||
import { JwtModule } from '@nestjs/jwt';
|
import { JwtModule } from '@nestjs/jwt';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { EvenementsAgenda } from 'src/entities/evenements_agenda.entity';
|
import { AbsencesGarde } from 'src/entities/absences_garde.entity';
|
||||||
import { AmChildren } from 'src/entities/am_children.entity';
|
import { AmChildren } from 'src/entities/am_children.entity';
|
||||||
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
||||||
import { EvenementsAgendaController } from './evenements-agenda.controller';
|
import { AbsencesGardeController } from './absences-garde.controller';
|
||||||
import { EvenementsAgendaService } from './evenements-agenda.service';
|
import { AbsencesGardeService } from './absences-garde.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forFeature([EvenementsAgenda, AmChildren, ParentsChildren]),
|
TypeOrmModule.forFeature([AbsencesGarde, AmChildren, ParentsChildren]),
|
||||||
JwtModule.registerAsync({
|
JwtModule.registerAsync({
|
||||||
imports: [ConfigModule],
|
imports: [ConfigModule],
|
||||||
useFactory: (config: ConfigService) => ({
|
useFactory: (config: ConfigService) => ({
|
||||||
@@ -20,8 +20,8 @@ import { EvenementsAgendaService } from './evenements-agenda.service';
|
|||||||
inject: [ConfigService],
|
inject: [ConfigService],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
controllers: [EvenementsAgendaController],
|
controllers: [AbsencesGardeController],
|
||||||
providers: [EvenementsAgendaService],
|
providers: [AbsencesGardeService],
|
||||||
exports: [EvenementsAgendaService],
|
exports: [AbsencesGardeService],
|
||||||
})
|
})
|
||||||
export class EvenementsAgendaModule {}
|
export class AbsencesGardeModule {}
|
||||||
+20
-20
@@ -1,18 +1,18 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||||
import { ForbiddenException, BadRequestException } from '@nestjs/common';
|
import { ForbiddenException, BadRequestException } from '@nestjs/common';
|
||||||
import { EvenementsAgendaService } from './evenements-agenda.service';
|
import { AbsencesGardeService } from './absences-garde.service';
|
||||||
import {
|
import {
|
||||||
EvenementsAgenda,
|
AbsencesGarde,
|
||||||
StatutEvenementAgendaType,
|
StatutAbsenceGardeType,
|
||||||
TypeEvenementAgendaType,
|
TypeAbsenceGardeType,
|
||||||
} from 'src/entities/evenements_agenda.entity';
|
} from 'src/entities/absences_garde.entity';
|
||||||
import { AmChildren } from 'src/entities/am_children.entity';
|
import { AmChildren } from 'src/entities/am_children.entity';
|
||||||
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
||||||
import { RoleType } from 'src/entities/users.entity';
|
import { RoleType } from 'src/entities/users.entity';
|
||||||
|
|
||||||
describe('EvenementsAgendaService (#172)', () => {
|
describe('AbsencesGardeService (#172)', () => {
|
||||||
let service: EvenementsAgendaService;
|
let service: AbsencesGardeService;
|
||||||
const absencesRepo = {
|
const absencesRepo = {
|
||||||
create: jest.fn((x) => x),
|
create: jest.fn((x) => x),
|
||||||
save: jest.fn(async (x) => ({
|
save: jest.fn(async (x) => ({
|
||||||
@@ -37,8 +37,8 @@ describe('EvenementsAgendaService (#172)', () => {
|
|||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
providers: [
|
providers: [
|
||||||
EvenementsAgendaService,
|
AbsencesGardeService,
|
||||||
{ provide: getRepositoryToken(EvenementsAgenda), useValue: absencesRepo },
|
{ provide: getRepositoryToken(AbsencesGarde), useValue: absencesRepo },
|
||||||
{ provide: getRepositoryToken(AmChildren), useValue: amChildrenRepo },
|
{ provide: getRepositoryToken(AmChildren), useValue: amChildrenRepo },
|
||||||
{
|
{
|
||||||
provide: getRepositoryToken(ParentsChildren),
|
provide: getRepositoryToken(ParentsChildren),
|
||||||
@@ -46,7 +46,7 @@ describe('EvenementsAgendaService (#172)', () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
}).compile();
|
}).compile();
|
||||||
service = module.get(EvenementsAgendaService);
|
service = module.get(AbsencesGardeService);
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -68,10 +68,10 @@ describe('EvenementsAgendaService (#172)', () => {
|
|||||||
absencesRepo.findOne.mockResolvedValue({
|
absencesRepo.findOne.mockResolvedValue({
|
||||||
id: 'abs-1',
|
id: 'abs-1',
|
||||||
id_placement: 'pl-1',
|
id_placement: 'pl-1',
|
||||||
type: TypeEvenementAgendaType.ABSENCE_ENFANT,
|
type: TypeAbsenceGardeType.ABSENCE_ENFANT,
|
||||||
date_debut: '2026-10-01',
|
date_debut: '2026-10-01',
|
||||||
date_fin: '2026-10-02',
|
date_fin: '2026-10-02',
|
||||||
statut: StatutEvenementAgendaType.ACCEPTE,
|
statut: StatutAbsenceGardeType.ACCEPTE,
|
||||||
expire_at: new Date('9999-12-31'),
|
expire_at: new Date('9999-12-31'),
|
||||||
cree_le: new Date(),
|
cree_le: new Date(),
|
||||||
modifie_le: new Date(),
|
modifie_le: new Date(),
|
||||||
@@ -85,15 +85,15 @@ describe('EvenementsAgendaService (#172)', () => {
|
|||||||
|
|
||||||
const res = await service.creer('p-1', RoleType.PARENT, {
|
const res = await service.creer('p-1', RoleType.PARENT, {
|
||||||
id_placement: 'pl-1',
|
id_placement: 'pl-1',
|
||||||
type: TypeEvenementAgendaType.ABSENCE_ENFANT,
|
type: TypeAbsenceGardeType.ABSENCE_ENFANT,
|
||||||
date_debut: '2026-10-01',
|
date_debut: '2026-10-01',
|
||||||
date_fin: '2026-10-02',
|
date_fin: '2026-10-02',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(absencesRepo.save).toHaveBeenCalled();
|
expect(absencesRepo.save).toHaveBeenCalled();
|
||||||
const savedArg = absencesRepo.save.mock.calls[0][0];
|
const savedArg = absencesRepo.save.mock.calls[0][0];
|
||||||
expect(savedArg.statut).toBe(StatutEvenementAgendaType.ACCEPTE);
|
expect(savedArg.statut).toBe(StatutAbsenceGardeType.ACCEPTE);
|
||||||
expect(res.type).toBe(TypeEvenementAgendaType.ABSENCE_ENFANT);
|
expect(res.type).toBe(TypeAbsenceGardeType.ABSENCE_ENFANT);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('parent ne peut pas créer un congé AM', async () => {
|
it('parent ne peut pas créer un congé AM', async () => {
|
||||||
@@ -110,7 +110,7 @@ describe('EvenementsAgendaService (#172)', () => {
|
|||||||
await expect(
|
await expect(
|
||||||
service.creer('p-1', RoleType.PARENT, {
|
service.creer('p-1', RoleType.PARENT, {
|
||||||
id_placement: 'pl-1',
|
id_placement: 'pl-1',
|
||||||
type: TypeEvenementAgendaType.CONGE_AM,
|
type: TypeAbsenceGardeType.CONGE_AM,
|
||||||
date_debut: '2026-10-01',
|
date_debut: '2026-10-01',
|
||||||
date_fin: '2026-10-05',
|
date_fin: '2026-10-05',
|
||||||
}),
|
}),
|
||||||
@@ -121,10 +121,10 @@ describe('EvenementsAgendaService (#172)', () => {
|
|||||||
absencesRepo.findOne.mockResolvedValue({
|
absencesRepo.findOne.mockResolvedValue({
|
||||||
id: 'abs-1',
|
id: 'abs-1',
|
||||||
id_placement: 'pl-1',
|
id_placement: 'pl-1',
|
||||||
type: TypeEvenementAgendaType.CONGE_AM,
|
type: TypeAbsenceGardeType.CONGE_AM,
|
||||||
date_debut: '2026-10-01',
|
date_debut: '2026-10-01',
|
||||||
date_fin: '2026-10-05',
|
date_fin: '2026-10-05',
|
||||||
statut: StatutEvenementAgendaType.EN_ATTENTE,
|
statut: StatutAbsenceGardeType.EN_ATTENTE,
|
||||||
expire_at: new Date(),
|
expire_at: new Date(),
|
||||||
});
|
});
|
||||||
amChildrenRepo.findOne.mockResolvedValue({
|
amChildrenRepo.findOne.mockResolvedValue({
|
||||||
@@ -140,7 +140,7 @@ describe('EvenementsAgendaService (#172)', () => {
|
|||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
service.maj('p-1', RoleType.PARENT, 'abs-1', {
|
service.maj('p-1', RoleType.PARENT, 'abs-1', {
|
||||||
statut: StatutEvenementAgendaType.REFUSE,
|
statut: StatutAbsenceGardeType.REFUSE,
|
||||||
}),
|
}),
|
||||||
).rejects.toBeInstanceOf(BadRequestException);
|
).rejects.toBeInstanceOf(BadRequestException);
|
||||||
});
|
});
|
||||||
@@ -159,7 +159,7 @@ describe('EvenementsAgendaService (#172)', () => {
|
|||||||
await expect(
|
await expect(
|
||||||
service.creer('p-1', RoleType.PARENT, {
|
service.creer('p-1', RoleType.PARENT, {
|
||||||
id_placement: 'pl-1',
|
id_placement: 'pl-1',
|
||||||
type: TypeEvenementAgendaType.ABSENCE_ENFANT,
|
type: TypeAbsenceGardeType.ABSENCE_ENFANT,
|
||||||
date_debut: '2026-10-10',
|
date_debut: '2026-10-10',
|
||||||
date_fin: '2026-10-01',
|
date_fin: '2026-10-01',
|
||||||
}),
|
}),
|
||||||
+55
-55
@@ -7,19 +7,19 @@ import {
|
|||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { In, IsNull, Repository } from 'typeorm';
|
import { In, IsNull, Repository } from 'typeorm';
|
||||||
import {
|
import {
|
||||||
EvenementsAgenda,
|
AbsencesGarde,
|
||||||
StatutEvenementAgendaType,
|
StatutAbsenceGardeType,
|
||||||
TypeEvenementAgendaType,
|
TypeAbsenceGardeType,
|
||||||
} from 'src/entities/evenements_agenda.entity';
|
} from 'src/entities/absences_garde.entity';
|
||||||
import { AmChildren } from 'src/entities/am_children.entity';
|
import { AmChildren } from 'src/entities/am_children.entity';
|
||||||
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
||||||
import { RoleType } from 'src/entities/users.entity';
|
import { RoleType } from 'src/entities/users.entity';
|
||||||
import {
|
import {
|
||||||
EvenementAgendaDto,
|
AbsenceGardeDto,
|
||||||
CreerEvenementAgendaDto,
|
CreerAbsenceGardeDto,
|
||||||
ListeEvenementsAgendaDto,
|
ListeAbsencesGardeDto,
|
||||||
MajEvenementAgendaDto,
|
MajAbsenceGardeDto,
|
||||||
} from './dto/evenements-agenda.dto';
|
} from './dto/absences-garde.dto';
|
||||||
|
|
||||||
const TTL_EN_ATTENTE_MS = 15 * 24 * 60 * 60 * 1000;
|
const TTL_EN_ATTENTE_MS = 15 * 24 * 60 * 60 * 1000;
|
||||||
const TTL_REFUSE_MS = 7 * 24 * 60 * 60 * 1000;
|
const TTL_REFUSE_MS = 7 * 24 * 60 * 60 * 1000;
|
||||||
@@ -27,10 +27,10 @@ const TTL_REFUSE_MS = 7 * 24 * 60 * 60 * 1000;
|
|||||||
const EXPIRE_ACCEPTE = new Date('9999-12-31T23:59:59.999Z');
|
const EXPIRE_ACCEPTE = new Date('9999-12-31T23:59:59.999Z');
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class EvenementsAgendaService {
|
export class AbsencesGardeService {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(EvenementsAgenda)
|
@InjectRepository(AbsencesGarde)
|
||||||
private readonly absencesRepo: Repository<EvenementsAgenda>,
|
private readonly absencesRepo: Repository<AbsencesGarde>,
|
||||||
@InjectRepository(AmChildren)
|
@InjectRepository(AmChildren)
|
||||||
private readonly amChildrenRepo: Repository<AmChildren>,
|
private readonly amChildrenRepo: Repository<AmChildren>,
|
||||||
@InjectRepository(ParentsChildren)
|
@InjectRepository(ParentsChildren)
|
||||||
@@ -42,12 +42,12 @@ export class EvenementsAgendaService {
|
|||||||
role: RoleType,
|
role: RoleType,
|
||||||
opts: {
|
opts: {
|
||||||
placementId?: string;
|
placementId?: string;
|
||||||
type?: TypeEvenementAgendaType;
|
type?: TypeAbsenceGardeType;
|
||||||
statut?: StatutEvenementAgendaType;
|
statut?: StatutAbsenceGardeType;
|
||||||
from?: string;
|
from?: string;
|
||||||
to?: string;
|
to?: string;
|
||||||
},
|
},
|
||||||
): Promise<ListeEvenementsAgendaDto> {
|
): Promise<ListeAbsencesGardeDto> {
|
||||||
const placementIds = await this.resolvePlacementIds(
|
const placementIds = await this.resolvePlacementIds(
|
||||||
userId,
|
userId,
|
||||||
role,
|
role,
|
||||||
@@ -86,8 +86,8 @@ export class EvenementsAgendaService {
|
|||||||
async creer(
|
async creer(
|
||||||
userId: string,
|
userId: string,
|
||||||
role: RoleType,
|
role: RoleType,
|
||||||
dto: CreerEvenementAgendaDto,
|
dto: CreerAbsenceGardeDto,
|
||||||
): Promise<EvenementAgendaDto> {
|
): Promise<AbsenceGardeDto> {
|
||||||
this.assertDates(dto.date_debut, dto.date_fin);
|
this.assertDates(dto.date_debut, dto.date_fin);
|
||||||
await this.assertCanAccessPlacement(userId, role, dto.id_placement);
|
await this.assertCanAccessPlacement(userId, role, dto.id_placement);
|
||||||
this.assertCanCreateType(role, dto.type);
|
this.assertCanCreateType(role, dto.type);
|
||||||
@@ -111,8 +111,8 @@ export class EvenementsAgendaService {
|
|||||||
userId: string,
|
userId: string,
|
||||||
role: RoleType,
|
role: RoleType,
|
||||||
id: string,
|
id: string,
|
||||||
dto: MajEvenementAgendaDto,
|
dto: MajAbsenceGardeDto,
|
||||||
): Promise<EvenementAgendaDto> {
|
): Promise<AbsenceGardeDto> {
|
||||||
const row = await this.absencesRepo.findOne({ where: { id } });
|
const row = await this.absencesRepo.findOne({ where: { id } });
|
||||||
if (!row) {
|
if (!row) {
|
||||||
throw new NotFoundException('Absence introuvable');
|
throw new NotFoundException('Absence introuvable');
|
||||||
@@ -128,15 +128,15 @@ export class EvenementsAgendaService {
|
|||||||
this.assertCanEditDates(role, row);
|
this.assertCanEditDates(role, row);
|
||||||
row.date_debut = debut;
|
row.date_debut = debut;
|
||||||
row.date_fin = fin;
|
row.date_fin = fin;
|
||||||
if (row.statut === StatutEvenementAgendaType.EN_ATTENTE) {
|
if (row.statut === StatutAbsenceGardeType.EN_ATTENTE) {
|
||||||
row.expire_at = this.expireAtFor(StatutEvenementAgendaType.EN_ATTENTE);
|
row.expire_at = this.expireAtFor(StatutAbsenceGardeType.EN_ATTENTE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dto.statut !== undefined && dto.statut !== row.statut) {
|
if (dto.statut !== undefined && dto.statut !== row.statut) {
|
||||||
this.assertCanChangeStatut(role, row, dto.statut, dto.motif);
|
this.assertCanChangeStatut(role, row, dto.statut, dto.motif);
|
||||||
if (
|
if (
|
||||||
dto.statut === StatutEvenementAgendaType.REFUSE &&
|
dto.statut === StatutAbsenceGardeType.REFUSE &&
|
||||||
(!dto.motif || !dto.motif.trim())
|
(!dto.motif || !dto.motif.trim())
|
||||||
) {
|
) {
|
||||||
throw new BadRequestException(
|
throw new BadRequestException(
|
||||||
@@ -169,7 +169,7 @@ export class EvenementsAgendaService {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
role === RoleType.PARENT &&
|
role === RoleType.PARENT &&
|
||||||
row.type !== TypeEvenementAgendaType.ABSENCE_ENFANT
|
row.type !== TypeAbsenceGardeType.ABSENCE_ENFANT
|
||||||
) {
|
) {
|
||||||
throw new ForbiddenException(
|
throw new ForbiddenException(
|
||||||
'Un parent ne peut supprimer que les absences enfant',
|
'Un parent ne peut supprimer que les absences enfant',
|
||||||
@@ -183,7 +183,7 @@ export class EvenementsAgendaService {
|
|||||||
id: string,
|
id: string,
|
||||||
userId: string,
|
userId: string,
|
||||||
role: RoleType,
|
role: RoleType,
|
||||||
): Promise<EvenementAgendaDto> {
|
): Promise<AbsenceGardeDto> {
|
||||||
const row = await this.absencesRepo.findOne({
|
const row = await this.absencesRepo.findOne({
|
||||||
where: { id },
|
where: { id },
|
||||||
relations: ['placement', 'placement.child', 'placement.am', 'placement.am.user'],
|
relations: ['placement', 'placement.child', 'placement.am', 'placement.am.user'],
|
||||||
@@ -195,19 +195,19 @@ export class EvenementsAgendaService {
|
|||||||
return this.toDto(row);
|
return this.toDto(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
private statutInitial(type: TypeEvenementAgendaType): StatutEvenementAgendaType {
|
private statutInitial(type: TypeAbsenceGardeType): StatutAbsenceGardeType {
|
||||||
if (type === TypeEvenementAgendaType.ABSENCE_ENFANT) {
|
if (type === TypeAbsenceGardeType.ABSENCE_ENFANT) {
|
||||||
return StatutEvenementAgendaType.ACCEPTE;
|
return StatutAbsenceGardeType.ACCEPTE;
|
||||||
}
|
}
|
||||||
return StatutEvenementAgendaType.EN_ATTENTE;
|
return StatutAbsenceGardeType.EN_ATTENTE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private expireAtFor(statut: StatutEvenementAgendaType): Date {
|
private expireAtFor(statut: StatutAbsenceGardeType): Date {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (statut === StatutEvenementAgendaType.ACCEPTE) {
|
if (statut === StatutAbsenceGardeType.ACCEPTE) {
|
||||||
return EXPIRE_ACCEPTE;
|
return EXPIRE_ACCEPTE;
|
||||||
}
|
}
|
||||||
if (statut === StatutEvenementAgendaType.REFUSE) {
|
if (statut === StatutAbsenceGardeType.REFUSE) {
|
||||||
return new Date(now + TTL_REFUSE_MS);
|
return new Date(now + TTL_REFUSE_MS);
|
||||||
}
|
}
|
||||||
return new Date(now + TTL_EN_ATTENTE_MS);
|
return new Date(now + TTL_EN_ATTENTE_MS);
|
||||||
@@ -221,9 +221,9 @@ export class EvenementsAgendaService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private assertCanCreateType(role: RoleType, type: TypeEvenementAgendaType): void {
|
private assertCanCreateType(role: RoleType, type: TypeAbsenceGardeType): void {
|
||||||
if (role === RoleType.PARENT) {
|
if (role === RoleType.PARENT) {
|
||||||
if (type !== TypeEvenementAgendaType.ABSENCE_ENFANT) {
|
if (type !== TypeAbsenceGardeType.ABSENCE_ENFANT) {
|
||||||
throw new ForbiddenException(
|
throw new ForbiddenException(
|
||||||
'Un parent ne peut créer que des absences enfant',
|
'Un parent ne peut créer que des absences enfant',
|
||||||
);
|
);
|
||||||
@@ -232,8 +232,8 @@ export class EvenementsAgendaService {
|
|||||||
}
|
}
|
||||||
if (role === RoleType.ASSISTANTE_MATERNELLE) {
|
if (role === RoleType.ASSISTANTE_MATERNELLE) {
|
||||||
if (
|
if (
|
||||||
type !== TypeEvenementAgendaType.CONGE_AM &&
|
type !== TypeAbsenceGardeType.CONGE_AM &&
|
||||||
type !== TypeEvenementAgendaType.ARRET_MALADIE_AM
|
type !== TypeAbsenceGardeType.ARRET_MALADIE_AM
|
||||||
) {
|
) {
|
||||||
throw new ForbiddenException(
|
throw new ForbiddenException(
|
||||||
'Une AM ne peut créer que congé ou arrêt maladie',
|
'Une AM ne peut créer que congé ou arrêt maladie',
|
||||||
@@ -246,10 +246,10 @@ export class EvenementsAgendaService {
|
|||||||
|
|
||||||
private assertCanEditDates(
|
private assertCanEditDates(
|
||||||
role: RoleType,
|
role: RoleType,
|
||||||
row: EvenementsAgenda,
|
row: AbsencesGarde,
|
||||||
): void {
|
): void {
|
||||||
if (role === RoleType.PARENT) {
|
if (role === RoleType.PARENT) {
|
||||||
if (row.type !== TypeEvenementAgendaType.ABSENCE_ENFANT) {
|
if (row.type !== TypeAbsenceGardeType.ABSENCE_ENFANT) {
|
||||||
throw new ForbiddenException(
|
throw new ForbiddenException(
|
||||||
'Un parent ne peut modifier que les absences enfant',
|
'Un parent ne peut modifier que les absences enfant',
|
||||||
);
|
);
|
||||||
@@ -258,13 +258,13 @@ export class EvenementsAgendaService {
|
|||||||
}
|
}
|
||||||
if (role === RoleType.ASSISTANTE_MATERNELLE) {
|
if (role === RoleType.ASSISTANTE_MATERNELLE) {
|
||||||
if (
|
if (
|
||||||
row.type === TypeEvenementAgendaType.CONGE_AM ||
|
row.type === TypeAbsenceGardeType.CONGE_AM ||
|
||||||
row.type === TypeEvenementAgendaType.ARRET_MALADIE_AM
|
row.type === TypeAbsenceGardeType.ARRET_MALADIE_AM
|
||||||
) {
|
) {
|
||||||
if (
|
if (
|
||||||
row.statut !== StatutEvenementAgendaType.EN_ATTENTE &&
|
row.statut !== StatutAbsenceGardeType.EN_ATTENTE &&
|
||||||
row.statut !== StatutEvenementAgendaType.REFUSE &&
|
row.statut !== StatutAbsenceGardeType.REFUSE &&
|
||||||
row.statut !== StatutEvenementAgendaType.ACCEPTE
|
row.statut !== StatutAbsenceGardeType.ACCEPTE
|
||||||
) {
|
) {
|
||||||
throw new ForbiddenException('Statut incompatible avec une modification');
|
throw new ForbiddenException('Statut incompatible avec une modification');
|
||||||
}
|
}
|
||||||
@@ -278,31 +278,31 @@ export class EvenementsAgendaService {
|
|||||||
|
|
||||||
private assertCanChangeStatut(
|
private assertCanChangeStatut(
|
||||||
role: RoleType,
|
role: RoleType,
|
||||||
row: EvenementsAgenda,
|
row: AbsencesGarde,
|
||||||
next: StatutEvenementAgendaType,
|
next: StatutAbsenceGardeType,
|
||||||
_motif?: string,
|
_motif?: string,
|
||||||
): void {
|
): void {
|
||||||
if (role === RoleType.PARENT) {
|
if (role === RoleType.PARENT) {
|
||||||
// Accept / refuse congé ; ack arrêt (accepte)
|
// Accept / refuse congé ; ack arrêt (accepte)
|
||||||
if (
|
if (
|
||||||
row.type === TypeEvenementAgendaType.CONGE_AM ||
|
row.type === TypeAbsenceGardeType.CONGE_AM ||
|
||||||
row.type === TypeEvenementAgendaType.ARRET_MALADIE_AM
|
row.type === TypeAbsenceGardeType.ARRET_MALADIE_AM
|
||||||
) {
|
) {
|
||||||
if (
|
if (
|
||||||
next !== StatutEvenementAgendaType.ACCEPTE &&
|
next !== StatutAbsenceGardeType.ACCEPTE &&
|
||||||
next !== StatutEvenementAgendaType.REFUSE
|
next !== StatutAbsenceGardeType.REFUSE
|
||||||
) {
|
) {
|
||||||
throw new BadRequestException('Transition de statut invalide');
|
throw new BadRequestException('Transition de statut invalide');
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
row.type === TypeEvenementAgendaType.ARRET_MALADIE_AM &&
|
row.type === TypeAbsenceGardeType.ARRET_MALADIE_AM &&
|
||||||
next === StatutEvenementAgendaType.REFUSE
|
next === StatutAbsenceGardeType.REFUSE
|
||||||
) {
|
) {
|
||||||
throw new BadRequestException(
|
throw new BadRequestException(
|
||||||
'Un arrêt maladie ne se refuse pas (accusé seulement)',
|
'Un arrêt maladie ne se refuse pas (accusé seulement)',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (row.statut !== StatutEvenementAgendaType.EN_ATTENTE) {
|
if (row.statut !== StatutAbsenceGardeType.EN_ATTENTE) {
|
||||||
throw new BadRequestException('Cette demande n’est plus en attente');
|
throw new BadRequestException('Cette demande n’est plus en attente');
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -314,9 +314,9 @@ export class EvenementsAgendaService {
|
|||||||
if (role === RoleType.ASSISTANTE_MATERNELLE) {
|
if (role === RoleType.ASSISTANTE_MATERNELLE) {
|
||||||
// Remise en attente après refus OU modification d’un congé déjà accepté (S2b)
|
// Remise en attente après refus OU modification d’un congé déjà accepté (S2b)
|
||||||
if (
|
if (
|
||||||
next === StatutEvenementAgendaType.EN_ATTENTE &&
|
next === StatutAbsenceGardeType.EN_ATTENTE &&
|
||||||
(row.statut === StatutEvenementAgendaType.REFUSE ||
|
(row.statut === StatutAbsenceGardeType.REFUSE ||
|
||||||
row.statut === StatutEvenementAgendaType.ACCEPTE)
|
row.statut === StatutAbsenceGardeType.ACCEPTE)
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -396,7 +396,7 @@ export class EvenementsAgendaService {
|
|||||||
throw new ForbiddenException('Rôle non autorisé');
|
throw new ForbiddenException('Rôle non autorisé');
|
||||||
}
|
}
|
||||||
|
|
||||||
private toDto(row: EvenementsAgenda): EvenementAgendaDto {
|
private toDto(row: AbsencesGarde): AbsenceGardeDto {
|
||||||
const child = row.placement?.child;
|
const child = row.placement?.child;
|
||||||
const amUser = row.placement?.am?.user;
|
const amUser = row.placement?.am?.user;
|
||||||
return {
|
return {
|
||||||
+19
-19
@@ -9,18 +9,18 @@ import {
|
|||||||
MinLength,
|
MinLength,
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
import {
|
import {
|
||||||
StatutEvenementAgendaType,
|
StatutAbsenceGardeType,
|
||||||
TypeEvenementAgendaType,
|
TypeAbsenceGardeType,
|
||||||
} from 'src/entities/evenements_agenda.entity';
|
} from 'src/entities/absences_garde.entity';
|
||||||
|
|
||||||
export class CreerEvenementAgendaDto {
|
export class CreerAbsenceGardeDto {
|
||||||
@ApiProperty({ description: 'Placement AM↔enfant (couple)' })
|
@ApiProperty({ description: 'Placement AM↔enfant (couple)' })
|
||||||
@IsUUID()
|
@IsUUID()
|
||||||
id_placement: string;
|
id_placement: string;
|
||||||
|
|
||||||
@ApiProperty({ enum: TypeEvenementAgendaType })
|
@ApiProperty({ enum: TypeAbsenceGardeType })
|
||||||
@IsEnum(TypeEvenementAgendaType)
|
@IsEnum(TypeAbsenceGardeType)
|
||||||
type: TypeEvenementAgendaType;
|
type: TypeAbsenceGardeType;
|
||||||
|
|
||||||
@ApiProperty({ example: '2026-10-01' })
|
@ApiProperty({ example: '2026-10-01' })
|
||||||
@IsDateString()
|
@IsDateString()
|
||||||
@@ -37,7 +37,7 @@ export class CreerEvenementAgendaDto {
|
|||||||
motif?: string;
|
motif?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MajEvenementAgendaDto {
|
export class MajAbsenceGardeDto {
|
||||||
@ApiPropertyOptional({ example: '2026-10-02' })
|
@ApiPropertyOptional({ example: '2026-10-02' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsDateString()
|
@IsDateString()
|
||||||
@@ -48,10 +48,10 @@ export class MajEvenementAgendaDto {
|
|||||||
@IsDateString()
|
@IsDateString()
|
||||||
date_fin?: string;
|
date_fin?: string;
|
||||||
|
|
||||||
@ApiPropertyOptional({ enum: StatutEvenementAgendaType })
|
@ApiPropertyOptional({ enum: StatutAbsenceGardeType })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsEnum(StatutEvenementAgendaType)
|
@IsEnum(StatutAbsenceGardeType)
|
||||||
statut?: StatutEvenementAgendaType;
|
statut?: StatutAbsenceGardeType;
|
||||||
|
|
||||||
@ApiPropertyOptional({
|
@ApiPropertyOptional({
|
||||||
description: 'Motivation de refus (parent) ou motif créateur',
|
description: 'Motivation de refus (parent) ou motif créateur',
|
||||||
@@ -63,15 +63,15 @@ export class MajEvenementAgendaDto {
|
|||||||
motif?: string;
|
motif?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EvenementAgendaDto {
|
export class AbsenceGardeDto {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
id_placement: string;
|
id_placement: string;
|
||||||
|
|
||||||
@ApiProperty({ enum: TypeEvenementAgendaType })
|
@ApiProperty({ enum: TypeAbsenceGardeType })
|
||||||
type: TypeEvenementAgendaType;
|
type: TypeAbsenceGardeType;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
date_debut: string;
|
date_debut: string;
|
||||||
@@ -79,8 +79,8 @@ export class EvenementAgendaDto {
|
|||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
date_fin: string;
|
date_fin: string;
|
||||||
|
|
||||||
@ApiProperty({ enum: StatutEvenementAgendaType })
|
@ApiProperty({ enum: StatutAbsenceGardeType })
|
||||||
statut: StatutEvenementAgendaType;
|
statut: StatutAbsenceGardeType;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
expire_at: string;
|
expire_at: string;
|
||||||
@@ -113,7 +113,7 @@ export class EvenementAgendaDto {
|
|||||||
modifie_le: string;
|
modifie_le: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ListeEvenementsAgendaDto {
|
export class ListeAbsencesGardeDto {
|
||||||
@ApiProperty({ type: [EvenementAgendaDto] })
|
@ApiProperty({ type: [AbsenceGardeDto] })
|
||||||
items: EvenementAgendaDto[];
|
items: AbsenceGardeDto[];
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export { AbsencesGardeModule } from './absences-garde.module';
|
||||||
|
export { AbsencesGardeService } from './absences-garde.service';
|
||||||
@@ -65,7 +65,7 @@ export class CardsController {
|
|||||||
@Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE)
|
@Roles(RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE)
|
||||||
@HttpCode(HttpStatus.CREATED)
|
@HttpCode(HttpStatus.CREATED)
|
||||||
@ApiOperation({
|
@ApiOperation({
|
||||||
summary: 'Créer une bulle (+ hook evenements_agenda) — #194',
|
summary: 'Créer une bulle (+ hook absences_garde) — #194',
|
||||||
})
|
})
|
||||||
@ApiBody({ type: CreerCarteDto })
|
@ApiBody({ type: CreerCarteDto })
|
||||||
@ApiResponse({ status: 201, type: CarteDto })
|
@ApiResponse({ status: 201, type: CarteDto })
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Module } from '@nestjs/common';
|
|||||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||||
import { JwtModule } from '@nestjs/jwt';
|
import { JwtModule } from '@nestjs/jwt';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { EvenementsAgendaModule } from '../evenements-agenda';
|
import { AbsencesGardeModule } from '../absences-garde';
|
||||||
import { CardType } from 'src/entities/card_types.entity';
|
import { CardType } from 'src/entities/card_types.entity';
|
||||||
import { CardInstance } from 'src/entities/card_instances.entity';
|
import { CardInstance } from 'src/entities/card_instances.entity';
|
||||||
import { CardAudienceMember } from 'src/entities/card_audience_members.entity';
|
import { CardAudienceMember } from 'src/entities/card_audience_members.entity';
|
||||||
@@ -16,7 +16,7 @@ import { CardsRealtimeService } from './cards-realtime.service';
|
|||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
EvenementsAgendaModule,
|
AbsencesGardeModule,
|
||||||
TypeOrmModule.forFeature([
|
TypeOrmModule.forFeature([
|
||||||
CardType,
|
CardType,
|
||||||
CardInstance,
|
CardInstance,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { getRepositoryToken } from '@nestjs/typeorm';
|
|||||||
import { ForbiddenException } from '@nestjs/common';
|
import { ForbiddenException } from '@nestjs/common';
|
||||||
import { CardsService } from './cards.service';
|
import { CardsService } from './cards.service';
|
||||||
import { CardsRealtimeService } from './cards-realtime.service';
|
import { CardsRealtimeService } from './cards-realtime.service';
|
||||||
import { EvenementsAgendaService } from '../evenements-agenda/evenements-agenda.service';
|
import { AbsencesGardeService } from '../absences-garde/absences-garde.service';
|
||||||
import { CardType, CardResponseModeType } from 'src/entities/card_types.entity';
|
import { CardType, CardResponseModeType } from 'src/entities/card_types.entity';
|
||||||
import {
|
import {
|
||||||
CardInstance,
|
CardInstance,
|
||||||
@@ -15,7 +15,7 @@ import { CardResponse } from 'src/entities/card_responses.entity';
|
|||||||
import { AmChildren } from 'src/entities/am_children.entity';
|
import { AmChildren } from 'src/entities/am_children.entity';
|
||||||
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
||||||
import { RoleType } from 'src/entities/users.entity';
|
import { RoleType } from 'src/entities/users.entity';
|
||||||
import { StatutEvenementAgendaType, TypeEvenementAgendaType } from 'src/entities/evenements_agenda.entity';
|
import { StatutAbsenceGardeType, TypeAbsenceGardeType } from 'src/entities/absences_garde.entity';
|
||||||
|
|
||||||
describe('CardsService (#194)', () => {
|
describe('CardsService (#194)', () => {
|
||||||
let service: CardsService;
|
let service: CardsService;
|
||||||
@@ -41,7 +41,7 @@ describe('CardsService (#194)', () => {
|
|||||||
};
|
};
|
||||||
const amChildrenRepo = { findOne: jest.fn() };
|
const amChildrenRepo = { findOne: jest.fn() };
|
||||||
const parentsChildrenRepo = { find: jest.fn(), findOne: jest.fn() };
|
const parentsChildrenRepo = { find: jest.fn(), findOne: jest.fn() };
|
||||||
const evenementsService = {
|
const absencesService = {
|
||||||
creer: jest.fn(),
|
creer: jest.fn(),
|
||||||
maj: jest.fn(),
|
maj: jest.fn(),
|
||||||
supprimer: jest.fn(),
|
supprimer: jest.fn(),
|
||||||
@@ -58,7 +58,7 @@ describe('CardsService (#194)', () => {
|
|||||||
{ provide: getRepositoryToken(CardResponse), useValue: responsesRepo },
|
{ provide: getRepositoryToken(CardResponse), useValue: responsesRepo },
|
||||||
{ provide: getRepositoryToken(AmChildren), useValue: amChildrenRepo },
|
{ provide: getRepositoryToken(AmChildren), useValue: amChildrenRepo },
|
||||||
{ provide: getRepositoryToken(ParentsChildren), useValue: parentsChildrenRepo },
|
{ provide: getRepositoryToken(ParentsChildren), useValue: parentsChildrenRepo },
|
||||||
{ provide: EvenementsAgendaService, useValue: evenementsService },
|
{ provide: AbsencesGardeService, useValue: absencesService },
|
||||||
{ provide: CardsRealtimeService, useValue: realtime },
|
{ provide: CardsRealtimeService, useValue: realtime },
|
||||||
],
|
],
|
||||||
}).compile();
|
}).compile();
|
||||||
@@ -88,10 +88,10 @@ describe('CardsService (#194)', () => {
|
|||||||
enfantId: 'e-1',
|
enfantId: 'e-1',
|
||||||
date_fin: null,
|
date_fin: null,
|
||||||
});
|
});
|
||||||
evenementsService.creer.mockResolvedValue({
|
absencesService.creer.mockResolvedValue({
|
||||||
id: 'abs-1',
|
id: 'abs-1',
|
||||||
type: TypeEvenementAgendaType.CONGE_AM,
|
type: TypeAbsenceGardeType.CONGE_AM,
|
||||||
statut: StatutEvenementAgendaType.EN_ATTENTE,
|
statut: StatutAbsenceGardeType.EN_ATTENTE,
|
||||||
});
|
});
|
||||||
parentsChildrenRepo.find.mockResolvedValue([
|
parentsChildrenRepo.find.mockResolvedValue([
|
||||||
{ parentId: 'p-1', enfantId: 'e-1' },
|
{ parentId: 'p-1', enfantId: 'e-1' },
|
||||||
@@ -101,7 +101,7 @@ describe('CardsService (#194)', () => {
|
|||||||
id: 'card-1',
|
id: 'card-1',
|
||||||
type_code: 'conge_am',
|
type_code: 'conge_am',
|
||||||
id_placement: 'pl-1',
|
id_placement: 'pl-1',
|
||||||
id_evenement: 'abs-1',
|
id_absence: 'abs-1',
|
||||||
cree_par: 'am-1',
|
cree_par: 'am-1',
|
||||||
operation: CardOperationType.CREATE,
|
operation: CardOperationType.CREATE,
|
||||||
statut: CardInstanceStatutType.OUVERTE,
|
statut: CardInstanceStatutType.OUVERTE,
|
||||||
@@ -130,7 +130,7 @@ describe('CardsService (#194)', () => {
|
|||||||
date_fin: '2026-11-07',
|
date_fin: '2026-11-07',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(evenementsService.creer).toHaveBeenCalled();
|
expect(absencesService.creer).toHaveBeenCalled();
|
||||||
expect(audienceRepo.save).toHaveBeenCalled();
|
expect(audienceRepo.save).toHaveBeenCalled();
|
||||||
expect(realtime.emitToUsers).toHaveBeenCalledWith(
|
expect(realtime.emitToUsers).toHaveBeenCalledWith(
|
||||||
['am-1', 'p-1', 'p-2'],
|
['am-1', 'p-1', 'p-2'],
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { IsNull, Repository } from 'typeorm';
|
import { IsNull, Repository } from 'typeorm';
|
||||||
import { EvenementsAgendaService } from '../evenements-agenda/evenements-agenda.service';
|
import { AbsencesGardeService } from '../absences-garde/absences-garde.service';
|
||||||
import {
|
import {
|
||||||
StatutEvenementAgendaType,
|
StatutAbsenceGardeType,
|
||||||
TypeEvenementAgendaType,
|
TypeAbsenceGardeType,
|
||||||
} from 'src/entities/evenements_agenda.entity';
|
} from 'src/entities/absences_garde.entity';
|
||||||
import { AmChildren } from 'src/entities/am_children.entity';
|
import { AmChildren } from 'src/entities/am_children.entity';
|
||||||
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
||||||
import { RoleType } from 'src/entities/users.entity';
|
import { RoleType } from 'src/entities/users.entity';
|
||||||
@@ -49,7 +49,7 @@ export class CardsService {
|
|||||||
private readonly amChildrenRepo: Repository<AmChildren>,
|
private readonly amChildrenRepo: Repository<AmChildren>,
|
||||||
@InjectRepository(ParentsChildren)
|
@InjectRepository(ParentsChildren)
|
||||||
private readonly parentsChildrenRepo: Repository<ParentsChildren>,
|
private readonly parentsChildrenRepo: Repository<ParentsChildren>,
|
||||||
private readonly evenementsService: EvenementsAgendaService,
|
private readonly absencesService: AbsencesGardeService,
|
||||||
private readonly realtime: CardsRealtimeService,
|
private readonly realtime: CardsRealtimeService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -110,11 +110,11 @@ export class CardsService {
|
|||||||
);
|
);
|
||||||
const operation = dto.operation ?? CardOperationType.CREATE;
|
const operation = dto.operation ?? CardOperationType.CREATE;
|
||||||
|
|
||||||
let absenceId = dto.id_evenement;
|
let absenceId = dto.id_absence;
|
||||||
const absenceType = this.mapAbsenceType(dto.type_code);
|
const absenceType = this.mapAbsenceType(dto.type_code);
|
||||||
|
|
||||||
if (operation === CardOperationType.CREATE) {
|
if (operation === CardOperationType.CREATE) {
|
||||||
const absence = await this.evenementsService.creer(userId, role, {
|
const absence = await this.absencesService.creer(userId, role, {
|
||||||
id_placement: dto.id_placement,
|
id_placement: dto.id_placement,
|
||||||
type: absenceType,
|
type: absenceType,
|
||||||
date_debut: dto.date_debut,
|
date_debut: dto.date_debut,
|
||||||
@@ -124,16 +124,16 @@ export class CardsService {
|
|||||||
absenceId = absence.id;
|
absenceId = absence.id;
|
||||||
} else {
|
} else {
|
||||||
if (!absenceId) {
|
if (!absenceId) {
|
||||||
throw new BadRequestException('id_evenement requis pour operation=update');
|
throw new BadRequestException('id_absence requis pour operation=update');
|
||||||
}
|
}
|
||||||
await this.evenementsService.maj(userId, role, absenceId, {
|
await this.absencesService.maj(userId, role, absenceId, {
|
||||||
date_debut: dto.date_debut,
|
date_debut: dto.date_debut,
|
||||||
date_fin: dto.date_fin,
|
date_fin: dto.date_fin,
|
||||||
motif: dto.motif,
|
motif: dto.motif,
|
||||||
// Congé accepté modifié → repasse en attente via cartes respond flow;
|
// Congé accepté modifié → repasse en attente via cartes respond flow;
|
||||||
// pour absence enfant update immédiat déjà fait.
|
// pour absence enfant update immédiat déjà fait.
|
||||||
...(dto.type_code === 'conge_am'
|
...(dto.type_code === 'conge_am'
|
||||||
? { statut: StatutEvenementAgendaType.EN_ATTENTE }
|
? { statut: StatutAbsenceGardeType.EN_ATTENTE }
|
||||||
: {}),
|
: {}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -146,7 +146,7 @@ export class CardsService {
|
|||||||
const card = this.cardsRepo.create({
|
const card = this.cardsRepo.create({
|
||||||
type_code: type.code,
|
type_code: type.code,
|
||||||
id_placement: dto.id_placement,
|
id_placement: dto.id_placement,
|
||||||
id_evenement: absenceId,
|
id_absence: absenceId,
|
||||||
cree_par: userId,
|
cree_par: userId,
|
||||||
operation,
|
operation,
|
||||||
statut: statutInitial,
|
statut: statutInitial,
|
||||||
@@ -204,22 +204,24 @@ export class CardsService {
|
|||||||
throw new BadRequestException('Motivation obligatoire en cas de refus');
|
throw new BadRequestException('Motivation obligatoire en cas de refus');
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.responsesRepo.insert({
|
await this.responsesRepo.save(
|
||||||
id_card: card.id,
|
this.responsesRepo.create({
|
||||||
id_utilisateur: userId,
|
id_card: card.id,
|
||||||
action: dto.action,
|
id_utilisateur: userId,
|
||||||
comment: dto.comment?.trim() || undefined,
|
action: dto.action,
|
||||||
});
|
comment: dto.comment?.trim(),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
if (card.id_evenement) {
|
if (card.id_absence) {
|
||||||
if (dto.action === CardResponseActionType.ACCEPT || dto.action === CardResponseActionType.ACK) {
|
if (dto.action === CardResponseActionType.ACCEPT || dto.action === CardResponseActionType.ACK) {
|
||||||
await this.evenementsService.maj(userId, role, card.id_evenement, {
|
await this.absencesService.maj(userId, role, card.id_absence, {
|
||||||
statut: StatutEvenementAgendaType.ACCEPTE,
|
statut: StatutAbsenceGardeType.ACCEPTE,
|
||||||
});
|
});
|
||||||
card.statut = CardInstanceStatutType.TRAITEE;
|
card.statut = CardInstanceStatutType.TRAITEE;
|
||||||
} else if (dto.action === CardResponseActionType.REFUSE) {
|
} else if (dto.action === CardResponseActionType.REFUSE) {
|
||||||
await this.evenementsService.maj(userId, role, card.id_evenement, {
|
await this.absencesService.maj(userId, role, card.id_absence, {
|
||||||
statut: StatutEvenementAgendaType.REFUSE,
|
statut: StatutAbsenceGardeType.REFUSE,
|
||||||
motif: dto.comment!.trim(),
|
motif: dto.comment!.trim(),
|
||||||
});
|
});
|
||||||
card.statut = CardInstanceStatutType.REFUSEE;
|
card.statut = CardInstanceStatutType.REFUSEE;
|
||||||
@@ -264,12 +266,12 @@ export class CardsService {
|
|||||||
throw new BadRequestException('Dates invalides');
|
throw new BadRequestException('Dates invalides');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (card.id_evenement) {
|
if (card.id_absence) {
|
||||||
await this.evenementsService.maj(userId, role, card.id_evenement, {
|
await this.absencesService.maj(userId, role, card.id_absence, {
|
||||||
date_debut: debut,
|
date_debut: debut,
|
||||||
date_fin: fin,
|
date_fin: fin,
|
||||||
motif: dto.motif,
|
motif: dto.motif,
|
||||||
statut: StatutEvenementAgendaType.EN_ATTENTE,
|
statut: StatutAbsenceGardeType.EN_ATTENTE,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,17 +300,17 @@ export class CardsService {
|
|||||||
throw new ForbiddenException('Seul le créateur peut supprimer cette carte');
|
throw new ForbiddenException('Seul le créateur peut supprimer cette carte');
|
||||||
}
|
}
|
||||||
const audienceIds = await this.audienceUserIds(card);
|
const audienceIds = await this.audienceUserIds(card);
|
||||||
if (card.id_evenement) {
|
if (card.id_absence) {
|
||||||
const absStatut =
|
const absStatut =
|
||||||
card.statut === CardInstanceStatutType.TRAITEE
|
card.statut === CardInstanceStatutType.TRAITEE
|
||||||
? null
|
? null
|
||||||
: card.id_evenement;
|
: card.id_absence;
|
||||||
// Supprime l’absence liée si pas encore acceptée définitivement
|
// Supprime l’absence liée si pas encore acceptée définitivement
|
||||||
if (
|
if (
|
||||||
card.statut === CardInstanceStatutType.OUVERTE ||
|
card.statut === CardInstanceStatutType.OUVERTE ||
|
||||||
card.statut === CardInstanceStatutType.REFUSEE
|
card.statut === CardInstanceStatutType.REFUSEE
|
||||||
) {
|
) {
|
||||||
await this.evenementsService.supprimer(userId, role, card.id_evenement);
|
await this.absencesService.supprimer(userId, role, card.id_absence);
|
||||||
}
|
}
|
||||||
void absStatut;
|
void absStatut;
|
||||||
}
|
}
|
||||||
@@ -336,13 +338,13 @@ export class CardsService {
|
|||||||
return rows.map((r) => r.id_utilisateur);
|
return rows.map((r) => r.id_utilisateur);
|
||||||
}
|
}
|
||||||
|
|
||||||
private mapAbsenceType(typeCode: string): TypeEvenementAgendaType {
|
private mapAbsenceType(typeCode: string): TypeAbsenceGardeType {
|
||||||
if (typeCode === 'absence_enfant' || typeCode === 'absence_enfant_modif') {
|
if (typeCode === 'absence_enfant' || typeCode === 'absence_enfant_modif') {
|
||||||
return TypeEvenementAgendaType.ABSENCE_ENFANT;
|
return TypeAbsenceGardeType.ABSENCE_ENFANT;
|
||||||
}
|
}
|
||||||
if (typeCode === 'conge_am') return TypeEvenementAgendaType.CONGE_AM;
|
if (typeCode === 'conge_am') return TypeAbsenceGardeType.CONGE_AM;
|
||||||
if (typeCode === 'arret_maladie_am') {
|
if (typeCode === 'arret_maladie_am') {
|
||||||
return TypeEvenementAgendaType.ARRET_MALADIE_AM;
|
return TypeAbsenceGardeType.ARRET_MALADIE_AM;
|
||||||
}
|
}
|
||||||
throw new BadRequestException(`Type non mappé à une absence: ${typeCode}`);
|
throw new BadRequestException(`Type non mappé à une absence: ${typeCode}`);
|
||||||
}
|
}
|
||||||
@@ -350,7 +352,7 @@ export class CardsService {
|
|||||||
private async linkAbsenceCard(absenceId: string, cardId: string): Promise<void> {
|
private async linkAbsenceCard(absenceId: string, cardId: string): Promise<void> {
|
||||||
// Update direct pour éviter droits maj vides
|
// Update direct pour éviter droits maj vides
|
||||||
await this.cardsRepo.manager.query(
|
await this.cardsRepo.manager.query(
|
||||||
`UPDATE evenements_agenda SET id_card_instance = $1, modifie_le = now() WHERE id = $2`,
|
`UPDATE absences_garde SET id_card_instance = $1, modifie_le = now() WHERE id = $2`,
|
||||||
[cardId, absenceId],
|
[cardId, absenceId],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -471,7 +473,7 @@ export class CardsService {
|
|||||||
titre: card.type?.titre ?? card.type_code,
|
titre: card.type?.titre ?? card.type_code,
|
||||||
couleur: card.type?.couleur ?? null,
|
couleur: card.type?.couleur ?? null,
|
||||||
id_placement: card.id_placement,
|
id_placement: card.id_placement,
|
||||||
id_evenement: card.id_evenement ?? null,
|
id_absence: card.id_absence ?? null,
|
||||||
operation: card.operation,
|
operation: card.operation,
|
||||||
statut: card.statut,
|
statut: card.statut,
|
||||||
payload: card.payload ?? {},
|
payload: card.payload ?? {},
|
||||||
|
|||||||
@@ -38,11 +38,11 @@ export class CreerCarteDto {
|
|||||||
motif?: string;
|
motif?: string;
|
||||||
|
|
||||||
@ApiPropertyOptional({
|
@ApiPropertyOptional({
|
||||||
description: 'Requis pour operation=update (même id evenements_agenda)',
|
description: 'Requis pour operation=update (même id absences_garde)',
|
||||||
})
|
})
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsUUID()
|
@IsUUID()
|
||||||
id_evenement?: string;
|
id_absence?: string;
|
||||||
|
|
||||||
@ApiPropertyOptional({ enum: CardOperationType, default: CardOperationType.CREATE })
|
@ApiPropertyOptional({ enum: CardOperationType, default: CardOperationType.CREATE })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@@ -98,7 +98,7 @@ export class CarteDto {
|
|||||||
id_placement: string;
|
id_placement: string;
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
id_evenement?: string | null;
|
id_absence?: string | null;
|
||||||
|
|
||||||
@ApiProperty({ enum: CardOperationType })
|
@ApiProperty({ enum: CardOperationType })
|
||||||
operation: CardOperationType;
|
operation: CardOperationType;
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
export { EvenementsAgendaModule } from './evenements-agenda.module';
|
|
||||||
export { EvenementsAgendaService } from './evenements-agenda.service';
|
|
||||||
+1
-29
@@ -10,10 +10,7 @@ describe('AssistantesMaternellesController', () => {
|
|||||||
const authServiceMock = {
|
const authServiceMock = {
|
||||||
createAmDossierStaff: jest.fn(),
|
createAmDossierStaff: jest.fn(),
|
||||||
};
|
};
|
||||||
const amServiceMock = {
|
const amServiceMock = {};
|
||||||
listerCouplesGarde: jest.fn(),
|
|
||||||
definirCoupleGardeCourant: jest.fn(),
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
@@ -69,29 +66,4 @@ describe('AssistantesMaternellesController', () => {
|
|||||||
);
|
);
|
||||||
expect(res.numero_dossier).toBe('2026-000001');
|
expect(res.numero_dossier).toBe('2026-000001');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('listerCouplesGarde délègue au service (#171)', async () => {
|
|
||||||
amServiceMock.listerCouplesGarde.mockResolvedValue({
|
|
||||||
couples: [],
|
|
||||||
couple_courant_id: null,
|
|
||||||
});
|
|
||||||
const res = await controller.listerCouplesGarde('am-uuid');
|
|
||||||
expect(amServiceMock.listerCouplesGarde).toHaveBeenCalledWith('am-uuid');
|
|
||||||
expect(res.couple_courant_id).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('definirCoupleGardeCourant délègue au service (#171)', async () => {
|
|
||||||
amServiceMock.definirCoupleGardeCourant.mockResolvedValue({
|
|
||||||
couples: [{ id: 'pl-1', courant: true }],
|
|
||||||
couple_courant_id: 'pl-1',
|
|
||||||
});
|
|
||||||
const res = await controller.definirCoupleGardeCourant('am-uuid', {
|
|
||||||
couple_id: 'pl-1',
|
|
||||||
});
|
|
||||||
expect(amServiceMock.definirCoupleGardeCourant).toHaveBeenCalledWith(
|
|
||||||
'am-uuid',
|
|
||||||
'pl-1',
|
|
||||||
);
|
|
||||||
expect(res.couple_courant_id).toBe('pl-1');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import {
|
|||||||
Controller,
|
Controller,
|
||||||
Get,
|
Get,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
|
||||||
Body,
|
Body,
|
||||||
Patch,
|
Patch,
|
||||||
Param,
|
Param,
|
||||||
@@ -21,8 +20,6 @@ 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 { StaffCreateAmDossierDto } from './dto/staff-create-am-dossier.dto';
|
import { StaffCreateAmDossierDto } from './dto/staff-create-am-dossier.dto';
|
||||||
import { StaffCreateAmDossierResponseDto } from './dto/staff-create-am-dossier-response.dto';
|
import { StaffCreateAmDossierResponseDto } from './dto/staff-create-am-dossier-response.dto';
|
||||||
import { CouplesGardeAmResponseDto } from './dto/couples-garde-am.dto';
|
|
||||||
import { DefinirCoupleGardeCourantAmDto } from './dto/definir-couple-garde-courant-am.dto';
|
|
||||||
import { RolesGuard } from 'src/common/guards/roles.guard';
|
import { RolesGuard } from 'src/common/guards/roles.guard';
|
||||||
import { AuthGuard } from 'src/common/guards/auth.guard';
|
import { AuthGuard } from 'src/common/guards/auth.guard';
|
||||||
import { User } from 'src/common/decorators/user.decorator';
|
import { User } from 'src/common/decorators/user.decorator';
|
||||||
@@ -86,36 +83,6 @@ export class AssistantesMaternellesController {
|
|||||||
return mapAmsForApi(ams);
|
return mapAmsForApi(ams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('me/couples-garde')
|
|
||||||
@Roles(RoleType.ASSISTANTE_MATERNELLE)
|
|
||||||
@ApiOperation({
|
|
||||||
summary: 'Couples de garde de l’AM connectée — ticket #171',
|
|
||||||
description:
|
|
||||||
'Placements actifs (enfant + parents) pour peupler le bandeau couple TdB AM, ' +
|
|
||||||
'avec indication du couple courant.',
|
|
||||||
})
|
|
||||||
@ApiResponse({ status: 200, type: CouplesGardeAmResponseDto })
|
|
||||||
listerCouplesGarde(
|
|
||||||
@User('id') userId: string,
|
|
||||||
): Promise<CouplesGardeAmResponseDto> {
|
|
||||||
return this.assistantesMaternellesService.listerCouplesGarde(userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Put('me/couples-garde/courant')
|
|
||||||
@Roles(RoleType.ASSISTANTE_MATERNELLE)
|
|
||||||
@ApiOperation({ summary: 'Définir le couple de garde courant (AM) — ticket #171' })
|
|
||||||
@ApiBody({ type: DefinirCoupleGardeCourantAmDto })
|
|
||||||
@ApiResponse({ status: 200, type: CouplesGardeAmResponseDto })
|
|
||||||
definirCoupleGardeCourant(
|
|
||||||
@User('id') userId: string,
|
|
||||||
@Body() dto: DefinirCoupleGardeCourantAmDto,
|
|
||||||
): Promise<CouplesGardeAmResponseDto> {
|
|
||||||
return this.assistantesMaternellesService.definirCoupleGardeCourant(
|
|
||||||
userId,
|
|
||||||
dto.couple_id,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE, RoleType.ADMINISTRATEUR)
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE, RoleType.ADMINISTRATEUR)
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
@ApiParam({ name: 'id', description: "UUID de la nounou" })
|
@ApiParam({ name: 'id', description: "UUID de la nounou" })
|
||||||
|
|||||||
@@ -4,21 +4,13 @@ import { AssistantesMaternellesController } from './assistantes_maternelles.cont
|
|||||||
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
||||||
import { AmChildren } from 'src/entities/am_children.entity';
|
import { AmChildren } from 'src/entities/am_children.entity';
|
||||||
import { Children } from 'src/entities/children.entity';
|
import { Children } from 'src/entities/children.entity';
|
||||||
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { Users } from 'src/entities/users.entity';
|
import { Users } from 'src/entities/users.entity';
|
||||||
import { AuthModule } from '../auth/auth.module';
|
import { AuthModule } from '../auth/auth.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [TypeOrmModule.forFeature([AssistanteMaternelle, AmChildren, Children, Users]),
|
||||||
TypeOrmModule.forFeature([
|
AuthModule
|
||||||
AssistanteMaternelle,
|
|
||||||
AmChildren,
|
|
||||||
Children,
|
|
||||||
Users,
|
|
||||||
ParentsChildren,
|
|
||||||
]),
|
|
||||||
AuthModule,
|
|
||||||
],
|
],
|
||||||
controllers: [AssistantesMaternellesController],
|
controllers: [AssistantesMaternellesController],
|
||||||
providers: [AssistantesMaternellesService],
|
providers: [AssistantesMaternellesService],
|
||||||
@@ -27,4 +19,4 @@ import { AuthModule } from '../auth/auth.module';
|
|||||||
TypeOrmModule,
|
TypeOrmModule,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AssistantesMaternellesModule {}
|
export class AssistantesMaternellesModule { }
|
||||||
|
|||||||
+4
-136
@@ -1,150 +1,18 @@
|
|||||||
import { NotFoundException } from '@nestjs/common';
|
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
|
||||||
import { AssistantesMaternellesService } from './assistantes_maternelles.service';
|
import { AssistantesMaternellesService } from './assistantes_maternelles.service';
|
||||||
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
|
||||||
import { Users } from 'src/entities/users.entity';
|
|
||||||
import { AmChildren } from 'src/entities/am_children.entity';
|
|
||||||
import { Children } from 'src/entities/children.entity';
|
|
||||||
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
|
||||||
|
|
||||||
describe('AssistantesMaternellesService — couples de garde (#171)', () => {
|
describe('AssistantesMaternellesService', () => {
|
||||||
let service: AssistantesMaternellesService;
|
let service: AssistantesMaternellesService;
|
||||||
|
|
||||||
const amRepo = { findOne: jest.fn(), update: jest.fn() };
|
|
||||||
const usersRepo = {};
|
|
||||||
const amChildrenRepo = { find: jest.fn(), findOne: jest.fn() };
|
|
||||||
const childrenRepo = {};
|
|
||||||
const parentsChildrenRepo = { find: jest.fn() };
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
jest.clearAllMocks();
|
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
providers: [
|
providers: [AssistantesMaternellesService],
|
||||||
AssistantesMaternellesService,
|
|
||||||
{ provide: getRepositoryToken(AssistanteMaternelle), useValue: amRepo },
|
|
||||||
{ provide: getRepositoryToken(Users), useValue: usersRepo },
|
|
||||||
{ provide: getRepositoryToken(AmChildren), useValue: amChildrenRepo },
|
|
||||||
{ provide: getRepositoryToken(Children), useValue: childrenRepo },
|
|
||||||
{
|
|
||||||
provide: getRepositoryToken(ParentsChildren),
|
|
||||||
useValue: parentsChildrenRepo,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}).compile();
|
}).compile();
|
||||||
service = module.get(AssistantesMaternellesService);
|
|
||||||
|
service = module.get<AssistantesMaternellesService>(AssistantesMaternellesService);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be defined', () => {
|
it('should be defined', () => {
|
||||||
expect(service).toBeDefined();
|
expect(service).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('listerCouplesGarde', () => {
|
|
||||||
it('retourne vide si aucun placement', async () => {
|
|
||||||
amRepo.findOne.mockResolvedValue({
|
|
||||||
user_id: 'am-1',
|
|
||||||
id_placement_garde_courant: null,
|
|
||||||
});
|
|
||||||
amChildrenRepo.find.mockResolvedValue([]);
|
|
||||||
const res = await service.listerCouplesGarde('am-1');
|
|
||||||
expect(res).toEqual({ couples: [], couple_courant_id: null });
|
|
||||||
expect(parentsChildrenRepo.find).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('mappe placements + parents et marque le courant', async () => {
|
|
||||||
amRepo.findOne.mockResolvedValue({
|
|
||||||
user_id: 'am-1',
|
|
||||||
id_placement_garde_courant: 'pl-2',
|
|
||||||
});
|
|
||||||
amChildrenRepo.find.mockResolvedValue([
|
|
||||||
{
|
|
||||||
id: 'pl-1',
|
|
||||||
enfantId: 'e1',
|
|
||||||
child: { id: 'e1', first_name: 'Léa', last_name: 'M', photo_url: null },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'pl-2',
|
|
||||||
enfantId: 'e2',
|
|
||||||
child: { id: 'e2', first_name: 'Emma', last_name: 'M', photo_url: null },
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
parentsChildrenRepo.find.mockResolvedValue([
|
|
||||||
{
|
|
||||||
parentId: 'p1',
|
|
||||||
enfantId: 'e1',
|
|
||||||
parent: { user: { prenom: 'Claire', nom: 'Martin', photo_url: null } },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
parentId: 'p2',
|
|
||||||
enfantId: 'e1',
|
|
||||||
parent: { user: { prenom: 'Thomas', nom: 'Martin', photo_url: null } },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
parentId: 'p1',
|
|
||||||
enfantId: 'e2',
|
|
||||||
parent: { user: { prenom: 'Claire', nom: 'Martin', photo_url: null } },
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const res = await service.listerCouplesGarde('am-1');
|
|
||||||
expect(res.couples).toHaveLength(2);
|
|
||||||
expect(res.couple_courant_id).toBe('pl-2');
|
|
||||||
expect(res.couples[1].courant).toBe(true);
|
|
||||||
expect(res.couples[0].parents).toHaveLength(2);
|
|
||||||
expect(res.couples[0].parents[0].prenom).toBe('Claire');
|
|
||||||
expect(res.couples[0].enfant.prenom).toBe('Léa');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('404 si AM inconnue', async () => {
|
|
||||||
amRepo.findOne.mockResolvedValue(null);
|
|
||||||
await expect(service.listerCouplesGarde('x')).rejects.toBeInstanceOf(
|
|
||||||
NotFoundException,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definirCoupleGardeCourant', () => {
|
|
||||||
it('persiste si le placement appartient à l’AM', async () => {
|
|
||||||
amRepo.findOne.mockResolvedValue({
|
|
||||||
user_id: 'am-1',
|
|
||||||
id_placement_garde_courant: null,
|
|
||||||
});
|
|
||||||
amChildrenRepo.findOne.mockResolvedValue({
|
|
||||||
id: 'pl-1',
|
|
||||||
amId: 'am-1',
|
|
||||||
enfantId: 'e1',
|
|
||||||
});
|
|
||||||
amRepo.update.mockResolvedValue({ affected: 1 });
|
|
||||||
amChildrenRepo.find.mockResolvedValue([
|
|
||||||
{
|
|
||||||
id: 'pl-1',
|
|
||||||
enfantId: 'e1',
|
|
||||||
child: { id: 'e1', first_name: 'Léa', last_name: null, photo_url: null },
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
parentsChildrenRepo.find.mockResolvedValue([
|
|
||||||
{
|
|
||||||
parentId: 'p1',
|
|
||||||
enfantId: 'e1',
|
|
||||||
parent: { user: { prenom: 'Claire', nom: 'M', photo_url: null } },
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const res = await service.definirCoupleGardeCourant('am-1', 'pl-1');
|
|
||||||
expect(amRepo.update).toHaveBeenCalledWith(
|
|
||||||
{ user_id: 'am-1' },
|
|
||||||
{ id_placement_garde_courant: 'pl-1' },
|
|
||||||
);
|
|
||||||
expect(res.couple_courant_id).toBe('pl-1');
|
|
||||||
expect(res.couples[0].courant).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('404 si placement d’une autre AM', async () => {
|
|
||||||
amRepo.findOne.mockResolvedValue({ user_id: 'am-1' });
|
|
||||||
amChildrenRepo.findOne.mockResolvedValue(null);
|
|
||||||
await expect(
|
|
||||||
service.definirCoupleGardeCourant('am-1', 'pl-x'),
|
|
||||||
).rejects.toBeInstanceOf(NotFoundException);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,16 +5,14 @@ import {
|
|||||||
NotFoundException,
|
NotFoundException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { In, IsNull, Repository } from 'typeorm';
|
import { IsNull, Repository } from 'typeorm';
|
||||||
import { RoleType, Users } from 'src/entities/users.entity';
|
import { RoleType, Users } from 'src/entities/users.entity';
|
||||||
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
||||||
import { AmChildren } from 'src/entities/am_children.entity';
|
import { AmChildren } from 'src/entities/am_children.entity';
|
||||||
import { Children, StatutEnfantType } from 'src/entities/children.entity';
|
import { Children, StatutEnfantType } from 'src/entities/children.entity';
|
||||||
import { ParentsChildren } from 'src/entities/parents_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 { CouplesGardeAmResponseDto } from './dto/couples-garde-am.dto';
|
|
||||||
import { validateNir } from 'src/common/utils/nir.util';
|
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;
|
||||||
@@ -30,8 +28,6 @@ export class AssistantesMaternellesService {
|
|||||||
private readonly amChildrenRepository: Repository<AmChildren>,
|
private readonly amChildrenRepository: Repository<AmChildren>,
|
||||||
@InjectRepository(Children)
|
@InjectRepository(Children)
|
||||||
private readonly childrenRepository: Repository<Children>,
|
private readonly childrenRepository: Repository<Children>,
|
||||||
@InjectRepository(ParentsChildren)
|
|
||||||
private readonly parentsChildrenRepository: Repository<ParentsChildren>,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async create(dto: CreateAssistanteDto): Promise<AssistanteMaternelle> {
|
async create(dto: CreateAssistanteDto): Promise<AssistanteMaternelle> {
|
||||||
@@ -268,107 +264,4 @@ export class AssistantesMaternellesService {
|
|||||||
await this.assistantesMaternelleRepository.delete(id);
|
await this.assistantesMaternelleRepository.delete(id);
|
||||||
return { message: 'Assistante maternelle supprimée' };
|
return { message: 'Assistante maternelle supprimée' };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Liste les couples de garde (enfant ↔ parents) de l’AM connectée — ticket #171.
|
|
||||||
* Un couple = un placement actif dans enfants_assistantes_maternelles pour cette AM.
|
|
||||||
*/
|
|
||||||
async listerCouplesGarde(amUserId: string): Promise<CouplesGardeAmResponseDto> {
|
|
||||||
const am = await this.assistantesMaternelleRepository.findOne({
|
|
||||||
where: { user_id: amUserId },
|
|
||||||
});
|
|
||||||
if (!am) {
|
|
||||||
throw new NotFoundException('Assistante maternelle introuvable');
|
|
||||||
}
|
|
||||||
|
|
||||||
const placements = await this.amChildrenRepository.find({
|
|
||||||
where: { amId: amUserId, date_fin: IsNull() },
|
|
||||||
relations: ['child'],
|
|
||||||
order: { date_debut: 'ASC' },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (placements.length === 0) {
|
|
||||||
return { couples: [], couple_courant_id: null };
|
|
||||||
}
|
|
||||||
|
|
||||||
const enfantIds = placements.map((p) => p.enfantId);
|
|
||||||
const liens = await this.parentsChildrenRepository.find({
|
|
||||||
where: { enfantId: In(enfantIds) },
|
|
||||||
relations: ['parent', 'parent.user'],
|
|
||||||
});
|
|
||||||
const parentsByEnfant = new Map<
|
|
||||||
string,
|
|
||||||
{ id: string; prenom: string | null; nom: string | null; photo_url: string | null }[]
|
|
||||||
>();
|
|
||||||
for (const l of liens) {
|
|
||||||
const list = parentsByEnfant.get(l.enfantId) ?? [];
|
|
||||||
const u = l.parent?.user;
|
|
||||||
list.push({
|
|
||||||
id: l.parentId,
|
|
||||||
prenom: u?.prenom ?? null,
|
|
||||||
nom: u?.nom ?? null,
|
|
||||||
photo_url: u?.photo_url ?? null,
|
|
||||||
});
|
|
||||||
parentsByEnfant.set(l.enfantId, list);
|
|
||||||
}
|
|
||||||
|
|
||||||
let idCourant = am.id_placement_garde_courant ?? null;
|
|
||||||
const idsValides = new Set(placements.map((p) => p.id));
|
|
||||||
if (idCourant && !idsValides.has(idCourant)) {
|
|
||||||
idCourant = null;
|
|
||||||
await this.assistantesMaternelleRepository.update(
|
|
||||||
{ user_id: amUserId },
|
|
||||||
{ id_placement_garde_courant: () => 'NULL' },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!idCourant && placements.length === 1) {
|
|
||||||
idCourant = placements[0].id;
|
|
||||||
}
|
|
||||||
|
|
||||||
const couples = placements.map((p) => ({
|
|
||||||
id: p.id,
|
|
||||||
enfant: {
|
|
||||||
id: p.child.id,
|
|
||||||
prenom: p.child.first_name ?? null,
|
|
||||||
nom: p.child.last_name ?? null,
|
|
||||||
photo_url: p.child.photo_url ?? null,
|
|
||||||
},
|
|
||||||
parents: parentsByEnfant.get(p.enfantId) ?? [],
|
|
||||||
courant: idCourant != null && p.id === idCourant,
|
|
||||||
}));
|
|
||||||
|
|
||||||
return {
|
|
||||||
couples,
|
|
||||||
couple_courant_id: idCourant,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Persiste le couple de garde actif pour l’AM — ticket #171.
|
|
||||||
*/
|
|
||||||
async definirCoupleGardeCourant(
|
|
||||||
amUserId: string,
|
|
||||||
coupleId: string,
|
|
||||||
): Promise<CouplesGardeAmResponseDto> {
|
|
||||||
const am = await this.assistantesMaternelleRepository.findOne({
|
|
||||||
where: { user_id: amUserId },
|
|
||||||
});
|
|
||||||
if (!am) {
|
|
||||||
throw new NotFoundException('Assistante maternelle introuvable');
|
|
||||||
}
|
|
||||||
|
|
||||||
const placement = await this.amChildrenRepository.findOne({
|
|
||||||
where: { id: coupleId, amId: amUserId, date_fin: IsNull() },
|
|
||||||
});
|
|
||||||
if (!placement) {
|
|
||||||
throw new NotFoundException('Couple de garde introuvable ou inactif pour cette AM');
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.assistantesMaternelleRepository.update(
|
|
||||||
{ user_id: amUserId },
|
|
||||||
{ id_placement_garde_courant: coupleId },
|
|
||||||
);
|
|
||||||
|
|
||||||
return this.listerCouplesGarde(amUserId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
||||||
|
|
||||||
/** Identité minimale enfant — ticket #171 (miroir #168) */
|
|
||||||
export class CoupleGardeAmEnfantDto {
|
|
||||||
@ApiProperty({ format: 'uuid' })
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
prenom?: string | null;
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
nom?: string | null;
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
photo_url?: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Identité minimale parent pour bandeau AM — ticket #171 */
|
|
||||||
export class CoupleGardeAmParentDto {
|
|
||||||
@ApiProperty({ format: 'uuid', description: 'UUID utilisateur du parent' })
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
prenom?: string | null;
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
nom?: string | null;
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
photo_url?: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Un couple côté AM = placement actif enfant ↔ foyer parents.
|
|
||||||
* `id` = enfants_assistantes_maternelles.id (même clé que #168).
|
|
||||||
*/
|
|
||||||
export class CoupleGardeAmDto {
|
|
||||||
@ApiProperty({
|
|
||||||
format: 'uuid',
|
|
||||||
description: 'Id du placement (enfants_assistantes_maternelles.id)',
|
|
||||||
})
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@ApiProperty({ type: CoupleGardeAmEnfantDto })
|
|
||||||
enfant: CoupleGardeAmEnfantDto;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: [CoupleGardeAmParentDto],
|
|
||||||
description: 'Parents rattachés à l’enfant (0–2 typiquement)',
|
|
||||||
})
|
|
||||||
parents: CoupleGardeAmParentDto[];
|
|
||||||
|
|
||||||
@ApiProperty({ description: 'True si c’est le couple actuellement sélectionné' })
|
|
||||||
courant: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CouplesGardeAmResponseDto {
|
|
||||||
@ApiProperty({ type: [CoupleGardeAmDto] })
|
|
||||||
couples: CoupleGardeAmDto[];
|
|
||||||
|
|
||||||
@ApiPropertyOptional({
|
|
||||||
format: 'uuid',
|
|
||||||
nullable: true,
|
|
||||||
description: 'Id du couple courant (null si aucun)',
|
|
||||||
})
|
|
||||||
couple_courant_id: string | null;
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
|
||||||
import { IsNotEmpty, IsUUID } from 'class-validator';
|
|
||||||
|
|
||||||
/** Corps PUT couple de garde courant AM — ticket #171 */
|
|
||||||
export class DefinirCoupleGardeCourantAmDto {
|
|
||||||
@ApiProperty({
|
|
||||||
format: 'uuid',
|
|
||||||
description: 'Id du placement (enfants_assistantes_maternelles.id) à sélectionner',
|
|
||||||
})
|
|
||||||
@IsUUID()
|
|
||||||
@IsNotEmpty()
|
|
||||||
couple_id: string;
|
|
||||||
}
|
|
||||||
+16
-29
@@ -35,13 +35,13 @@ DO $$ BEGIN
|
|||||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_avenant_type') THEN
|
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_avenant_type') THEN
|
||||||
CREATE TYPE statut_avenant_type AS ENUM ('propose', 'accepte', 'refuse');
|
CREATE TYPE statut_avenant_type AS ENUM ('propose', 'accepte', 'refuse');
|
||||||
END IF;
|
END IF;
|
||||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'type_evenement_agenda_type') THEN
|
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'type_absence_garde_type') THEN
|
||||||
CREATE TYPE type_evenement_agenda_type AS ENUM (
|
CREATE TYPE type_absence_garde_type AS ENUM (
|
||||||
'absence_enfant', 'conge_am', 'arret_maladie_am'
|
'absence_enfant', 'conge_am', 'arret_maladie_am'
|
||||||
);
|
);
|
||||||
END IF;
|
END IF;
|
||||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_evenement_agenda_type') THEN
|
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_absence_garde_type') THEN
|
||||||
CREATE TYPE statut_evenement_agenda_type AS ENUM (
|
CREATE TYPE statut_absence_garde_type AS ENUM (
|
||||||
'en_attente', 'accepte', 'refuse'
|
'en_attente', 'accepte', 'refuse'
|
||||||
);
|
);
|
||||||
END IF;
|
END IF;
|
||||||
@@ -143,10 +143,7 @@ CREATE TABLE assistantes_maternelles (
|
|||||||
annee_experience SMALLINT,
|
annee_experience SMALLINT,
|
||||||
specialite VARCHAR(100),
|
specialite VARCHAR(100),
|
||||||
place_disponible INT,
|
place_disponible INT,
|
||||||
numero_dossier VARCHAR(20),
|
numero_dossier VARCHAR(20)
|
||||||
-- Préférence couple de garde actif (TdB quotidien AM) — ticket #171
|
|
||||||
-- FK ajoutée après création de enfants_assistantes_maternelles (voir ALTER plus bas)
|
|
||||||
id_placement_garde_courant UUID
|
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_assistantes_maternelles_numero_dossier
|
CREATE INDEX idx_assistantes_maternelles_numero_dossier
|
||||||
@@ -224,16 +221,6 @@ CREATE INDEX idx_parents_placement_garde_courant
|
|||||||
ON parents(id_placement_garde_courant)
|
ON parents(id_placement_garde_courant)
|
||||||
WHERE id_placement_garde_courant IS NOT NULL;
|
WHERE id_placement_garde_courant IS NOT NULL;
|
||||||
|
|
||||||
-- FK couple courant AM → placement (#171)
|
|
||||||
ALTER TABLE assistantes_maternelles
|
|
||||||
ADD CONSTRAINT fk_am_placement_garde_courant
|
|
||||||
FOREIGN KEY (id_placement_garde_courant)
|
|
||||||
REFERENCES enfants_assistantes_maternelles(id) ON DELETE SET NULL;
|
|
||||||
|
|
||||||
CREATE INDEX idx_am_placement_garde_courant
|
|
||||||
ON assistantes_maternelles(id_placement_garde_courant)
|
|
||||||
WHERE id_placement_garde_courant IS NOT NULL;
|
|
||||||
|
|
||||||
-- ==========================================================
|
-- ==========================================================
|
||||||
-- Table : dossier_famille (inscription parent — ticket #119)
|
-- Table : dossier_famille (inscription parent — ticket #119)
|
||||||
-- ==========================================================
|
-- ==========================================================
|
||||||
@@ -322,32 +309,32 @@ CREATE TABLE avenants_contrats (
|
|||||||
);
|
);
|
||||||
|
|
||||||
-- ==========================================================
|
-- ==========================================================
|
||||||
-- Table : evenements_agenda (vérité métier agenda (absences/congés/arrêt + futurs types))
|
-- Table : absences_garde (vérité métier absences/congés/arrêt)
|
||||||
-- 1 ligne = 1 période ; rattachement = placement AM↔enfant (#193)
|
-- 1 ligne = 1 période ; rattachement = placement AM↔enfant (#193)
|
||||||
-- ==========================================================
|
-- ==========================================================
|
||||||
CREATE TABLE evenements_agenda (
|
CREATE TABLE absences_garde (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
id_placement UUID NOT NULL
|
id_placement UUID NOT NULL
|
||||||
REFERENCES enfants_assistantes_maternelles(id) ON DELETE CASCADE,
|
REFERENCES enfants_assistantes_maternelles(id) ON DELETE CASCADE,
|
||||||
type type_evenement_agenda_type NOT NULL,
|
type type_absence_garde_type NOT NULL,
|
||||||
date_debut DATE NOT NULL,
|
date_debut DATE NOT NULL,
|
||||||
date_fin DATE NOT NULL,
|
date_fin DATE NOT NULL,
|
||||||
statut statut_evenement_agenda_type NOT NULL DEFAULT 'en_attente',
|
statut statut_absence_garde_type NOT NULL DEFAULT 'en_attente',
|
||||||
expire_at TIMESTAMPTZ NOT NULL,
|
expire_at TIMESTAMPTZ NOT NULL,
|
||||||
cree_par UUID REFERENCES utilisateurs(id) ON DELETE SET NULL,
|
cree_par UUID REFERENCES utilisateurs(id) ON DELETE SET NULL,
|
||||||
id_card_instance UUID,
|
id_card_instance UUID,
|
||||||
motif TEXT,
|
motif TEXT,
|
||||||
cree_le TIMESTAMPTZ NOT NULL DEFAULT now(),
|
cree_le TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||||
modifie_le TIMESTAMPTZ NOT NULL DEFAULT now(),
|
modifie_le TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||||
CONSTRAINT chk_evenements_agenda_dates CHECK (date_fin >= date_debut)
|
CONSTRAINT chk_absences_garde_dates CHECK (date_fin >= date_debut)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_evenements_agenda_placement_dates
|
CREATE INDEX idx_absences_garde_placement_dates
|
||||||
ON evenements_agenda (id_placement, date_debut, date_fin);
|
ON absences_garde (id_placement, date_debut, date_fin);
|
||||||
CREATE INDEX idx_evenements_agenda_placement_type_statut
|
CREATE INDEX idx_absences_garde_placement_type_statut
|
||||||
ON evenements_agenda (id_placement, type, statut);
|
ON absences_garde (id_placement, type, statut);
|
||||||
CREATE INDEX idx_evenements_agenda_expire_at
|
CREATE INDEX idx_absences_garde_expire_at
|
||||||
ON evenements_agenda (expire_at)
|
ON absences_garde (expire_at)
|
||||||
WHERE statut IN ('en_attente', 'refuse');
|
WHERE statut IN ('en_attente', 'refuse');
|
||||||
|
|
||||||
-- ==========================================================
|
-- ==========================================================
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ Ce document recense **toutes les valeurs énumérées** utilisées dans la base
|
|||||||
|
|
||||||
## 7) Type d’absence de garde — `type`
|
## 7) Type d’absence de garde — `type`
|
||||||
|
|
||||||
**Tables/colonnes** : `evenements_agenda.type`
|
**Tables/colonnes** : `absences_garde.type`
|
||||||
**Valeurs autorisées** :
|
**Valeurs autorisées** :
|
||||||
|
|
||||||
| Valeur | Description |
|
| Valeur | Description |
|
||||||
@@ -115,13 +115,13 @@ Ce document recense **toutes les valeurs énumérées** utilisées dans la base
|
|||||||
| `conge_am` | Congé de l’assistante maternelle |
|
| `conge_am` | Congé de l’assistante maternelle |
|
||||||
| `arret_maladie_am` | Arrêt maladie AM |
|
| `arret_maladie_am` | Arrêt maladie AM |
|
||||||
|
|
||||||
> Remplace l’ancien enum `type_evenement_type` / table `evenements` (supprimés ticket #205 / ex-#193).
|
> Remplace l’ancien enum `type_evenement_type` / table `evenements` (supprimés ticket #193).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 8) Statut d’absence de garde — `statut`
|
## 8) Statut d’absence de garde — `statut`
|
||||||
|
|
||||||
**Tables/colonnes** : `evenements_agenda.statut`
|
**Tables/colonnes** : `absences_garde.statut`
|
||||||
**Valeurs autorisées** :
|
**Valeurs autorisées** :
|
||||||
|
|
||||||
| Valeur | Description |
|
| Valeur | Description |
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ Documenter, de façon unique et partagée, les règles de suppression/mise à jo
|
|||||||
| **contrats(id_dossier)** → `dossiers(id)` | **CASCADE** | 1:1, contrat détruit si dossier supprimé |
|
| **contrats(id_dossier)** → `dossiers(id)` | **CASCADE** | 1:1, contrat détruit si dossier supprimé |
|
||||||
| **avenants_contrats(id_contrat)** → `contrats(id)` | **CASCADE** | Avenants détruits avec le contrat |
|
| **avenants_contrats(id_contrat)** → `contrats(id)` | **CASCADE** | Avenants détruits avec le contrat |
|
||||||
| **avenants_contrats(initie_par)** → `utilisateurs(id)` | **SET NULL** | Historiser l’avenant sans bloquer |
|
| **avenants_contrats(initie_par)** → `utilisateurs(id)` | **SET NULL** | Historiser l’avenant sans bloquer |
|
||||||
| **evenements_agenda(id_placement)** → `enfants_assistantes_maternelles(id)` | **CASCADE** | Plus de couple = plus d’absences |
|
| **absences_garde(id_placement)** → `enfants_assistantes_maternelles(id)` | **CASCADE** | Plus de couple = plus d’absences |
|
||||||
| **evenements_agenda(cree_par)** → `utilisateurs(id)` | **SET NULL** | Conserver la période si user supprimé |
|
| **absences_garde(cree_par)** → `utilisateurs(id)` | **SET NULL** | Conserver la période si user supprimé |
|
||||||
| **signalements_bugs(id_utilisateur)** → `utilisateurs(id)` | **SET NULL** | Conserver le ticket même si compte supprimé |
|
| **signalements_bugs(id_utilisateur)** → `utilisateurs(id)` | **SET NULL** | Conserver le ticket même si compte supprimé |
|
||||||
| **uploads(id_utilisateur)** → `utilisateurs(id)` | **SET NULL** | Fichier reste référencé sans l’auteur |
|
| **uploads(id_utilisateur)** → `utilisateurs(id)` | **SET NULL** | Fichier reste référencé sans l’auteur |
|
||||||
| **notifications(id_utilisateur)** → `utilisateurs(id)` | **CASCADE** | Notifications propres à l’utilisateur |
|
| **notifications(id_utilisateur)** → `utilisateurs(id)` | **CASCADE** | Notifications propres à l’utilisateur |
|
||||||
@@ -77,8 +77,8 @@ Documenter, de façon unique et partagée, les règles de suppression/mise à jo
|
|||||||
- `avenants_contrats.initie_par` → **SET NULL**
|
- `avenants_contrats.initie_par` → **SET NULL**
|
||||||
|
|
||||||
### Événements
|
### Événements
|
||||||
- `evenements_agenda.id_placement` → **CASCADE**
|
- `absences_garde.id_placement` → **CASCADE**
|
||||||
- `evenements_agenda.cree_par` → **SET NULL**
|
- `absences_garde.cree_par` → **SET NULL**
|
||||||
|
|
||||||
### Divers
|
### Divers
|
||||||
- `signalements_bugs.id_utilisateur` → **SET NULL**
|
- `signalements_bugs.id_utilisateur` → **SET NULL**
|
||||||
@@ -105,7 +105,7 @@ Documenter, de façon unique et partagée, les règles de suppression/mise à jo
|
|||||||
|
|
||||||
4. **Suppression d’un enfant**
|
4. **Suppression d’un enfant**
|
||||||
- Supprimer `enfants(id=childA)`
|
- Supprimer `enfants(id=childA)`
|
||||||
- Attendu : `enfants_parents` (CASCADE), `dossiers` du childA (CASCADE), `evenements_agenda` des placements du childA (CASCADE via EAM).
|
- Attendu : `enfants_parents` (CASCADE), `dossiers` du childA (CASCADE), `absences_garde` des placements du childA (CASCADE via EAM).
|
||||||
|
|
||||||
5. **Suppression d’un utilisateur AM**
|
5. **Suppression d’un utilisateur AM**
|
||||||
- Supprimer `utilisateurs(id=amB)`
|
- Supprimer `utilisateurs(id=amB)`
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
-- Ticket #171 — Couple de garde courant (préférence AM)
|
|
||||||
-- Idempotent : safe à rejouer.
|
|
||||||
|
|
||||||
ALTER TABLE assistantes_maternelles
|
|
||||||
ADD COLUMN IF NOT EXISTS id_placement_garde_courant UUID
|
|
||||||
REFERENCES enfants_assistantes_maternelles(id) ON DELETE SET NULL;
|
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_am_placement_garde_courant
|
|
||||||
ON assistantes_maternelles(id_placement_garde_courant)
|
|
||||||
WHERE id_placement_garde_courant IS NOT NULL;
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
-- Ticket #205 — Renommer absences_garde → evenements_agenda
|
|
||||||
-- Migration base live. Idempotent autant que possible.
|
|
||||||
|
|
||||||
-- ---------------------------------------------------------------------------
|
|
||||||
-- 1. Table + enums
|
|
||||||
-- ---------------------------------------------------------------------------
|
|
||||||
DO $$
|
|
||||||
BEGIN
|
|
||||||
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'absences_garde')
|
|
||||||
AND NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'evenements_agenda') THEN
|
|
||||||
ALTER TABLE absences_garde RENAME TO evenements_agenda;
|
|
||||||
END IF;
|
|
||||||
END $$;
|
|
||||||
|
|
||||||
DO $$
|
|
||||||
BEGIN
|
|
||||||
IF EXISTS (SELECT 1 FROM pg_type WHERE typname = 'type_absence_garde_type')
|
|
||||||
AND NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'type_evenement_agenda_type') THEN
|
|
||||||
ALTER TYPE type_absence_garde_type RENAME TO type_evenement_agenda_type;
|
|
||||||
END IF;
|
|
||||||
IF EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_absence_garde_type')
|
|
||||||
AND NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_evenement_agenda_type') THEN
|
|
||||||
ALTER TYPE statut_absence_garde_type RENAME TO statut_evenement_agenda_type;
|
|
||||||
END IF;
|
|
||||||
END $$;
|
|
||||||
|
|
||||||
-- Contraintes / index (noms)
|
|
||||||
DO $$
|
|
||||||
BEGIN
|
|
||||||
IF EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'chk_absences_garde_dates') THEN
|
|
||||||
ALTER TABLE evenements_agenda RENAME CONSTRAINT chk_absences_garde_dates TO chk_evenements_agenda_dates;
|
|
||||||
END IF;
|
|
||||||
END $$;
|
|
||||||
|
|
||||||
ALTER INDEX IF EXISTS idx_absences_garde_placement_dates
|
|
||||||
RENAME TO idx_evenements_agenda_placement_dates;
|
|
||||||
ALTER INDEX IF EXISTS idx_absences_garde_placement_type_statut
|
|
||||||
RENAME TO idx_evenements_agenda_placement_type_statut;
|
|
||||||
ALTER INDEX IF EXISTS idx_absences_garde_expire_at
|
|
||||||
RENAME TO idx_evenements_agenda_expire_at;
|
|
||||||
ALTER INDEX IF EXISTS absences_garde_pkey
|
|
||||||
RENAME TO evenements_agenda_pkey;
|
|
||||||
|
|
||||||
COMMENT ON TABLE evenements_agenda IS
|
|
||||||
'Vérité métier agenda (absences, congés, arrêts, futurs soins/école/mairie/sorties…) par placement. Les cartes collectent ; cette table historise.';
|
|
||||||
COMMENT ON COLUMN evenements_agenda.expire_at IS
|
|
||||||
'Purge auto (job) pour en_attente/refuse. accepte → infinity.';
|
|
||||||
COMMENT ON COLUMN evenements_agenda.id_card_instance IS
|
|
||||||
'Réf. carte de collecte (module Cartes).';
|
|
||||||
|
|
||||||
-- ---------------------------------------------------------------------------
|
|
||||||
-- 2. card_instances.id_absence → id_evenement
|
|
||||||
-- ---------------------------------------------------------------------------
|
|
||||||
DO $$
|
|
||||||
BEGIN
|
|
||||||
IF EXISTS (
|
|
||||||
SELECT 1 FROM information_schema.columns
|
|
||||||
WHERE table_name = 'card_instances' AND column_name = 'id_absence'
|
|
||||||
) AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM information_schema.columns
|
|
||||||
WHERE table_name = 'card_instances' AND column_name = 'id_evenement'
|
|
||||||
) THEN
|
|
||||||
ALTER TABLE card_instances RENAME COLUMN id_absence TO id_evenement;
|
|
||||||
END IF;
|
|
||||||
END $$;
|
|
||||||
|
|
||||||
-- Recréer index si ancien nom
|
|
||||||
ALTER INDEX IF EXISTS idx_card_instances_absence
|
|
||||||
RENAME TO idx_card_instances_evenement;
|
|
||||||
|
|
||||||
-- FK : drop ancienne (nom variable) puis recreate
|
|
||||||
DO $$
|
|
||||||
DECLARE
|
|
||||||
fk_name text;
|
|
||||||
BEGIN
|
|
||||||
SELECT conname INTO fk_name
|
|
||||||
FROM pg_constraint
|
|
||||||
WHERE conrelid = 'card_instances'::regclass
|
|
||||||
AND contype = 'f'
|
|
||||||
AND pg_get_constraintdef(oid) ILIKE '%id_evenement%'
|
|
||||||
LIMIT 1;
|
|
||||||
|
|
||||||
IF fk_name IS NULL THEN
|
|
||||||
SELECT conname INTO fk_name
|
|
||||||
FROM pg_constraint
|
|
||||||
WHERE conrelid = 'card_instances'::regclass
|
|
||||||
AND contype = 'f'
|
|
||||||
AND pg_get_constraintdef(oid) ILIKE '%id_absence%'
|
|
||||||
LIMIT 1;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
IF fk_name IS NOT NULL THEN
|
|
||||||
EXECUTE format('ALTER TABLE card_instances DROP CONSTRAINT %I', fk_name);
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
IF NOT EXISTS (
|
|
||||||
SELECT 1 FROM pg_constraint
|
|
||||||
WHERE conname = 'card_instances_id_evenement_fkey'
|
|
||||||
) THEN
|
|
||||||
ALTER TABLE card_instances
|
|
||||||
ADD CONSTRAINT card_instances_id_evenement_fkey
|
|
||||||
FOREIGN KEY (id_evenement)
|
|
||||||
REFERENCES evenements_agenda(id)
|
|
||||||
ON DELETE SET NULL;
|
|
||||||
END IF;
|
|
||||||
END $$;
|
|
||||||
@@ -81,7 +81,7 @@ ORDER BY c.cree_le DESC;
|
|||||||
|
|
||||||
\echo '=== 9) Absences_garde (30 derniers jours) ====================='
|
\echo '=== 9) Absences_garde (30 derniers jours) ====================='
|
||||||
SELECT ag.id, ag.type, ag.id_placement, ag.date_debut, ag.date_fin, ag.statut, ag.expire_at
|
SELECT ag.id, ag.type, ag.id_placement, ag.date_debut, ag.date_fin, ag.statut, ag.expire_at
|
||||||
FROM evenements_agenda ag
|
FROM absences_garde ag
|
||||||
WHERE ag.date_debut >= (NOW()::date - INTERVAL '30 days')
|
WHERE ag.date_debut >= (NOW()::date - INTERVAL '30 days')
|
||||||
ORDER BY ag.date_debut DESC;
|
ORDER BY ag.date_debut DESC;
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ WHERE c.id IS NULL;
|
|||||||
|
|
||||||
-- Absences sans placement
|
-- Absences sans placement
|
||||||
SELECT ag.*
|
SELECT ag.*
|
||||||
FROM evenements_agenda ag
|
FROM absences_garde ag
|
||||||
LEFT JOIN enfants_assistantes_maternelles eam ON eam.id = ag.id_placement
|
LEFT JOIN enfants_assistantes_maternelles eam ON eam.id = ag.id_placement
|
||||||
WHERE eam.id IS NULL;
|
WHERE eam.id IS NULL;
|
||||||
|
|
||||||
@@ -150,10 +150,10 @@ WHERE m.id_dossier = 'dddddddd-dddd-dddd-dddd-dddddddddddd'
|
|||||||
ORDER BY m.cree_le DESC
|
ORDER BY m.cree_le DESC
|
||||||
LIMIT 20;
|
LIMIT 20;
|
||||||
|
|
||||||
-- Absences par placement et période (idx_evenements_agenda_placement_dates)
|
-- Absences par placement et période (idx_absences_garde_placement_dates)
|
||||||
EXPLAIN ANALYZE
|
EXPLAIN ANALYZE
|
||||||
SELECT ag.*
|
SELECT ag.*
|
||||||
FROM evenements_agenda ag
|
FROM absences_garde ag
|
||||||
WHERE ag.id_placement IS NOT NULL
|
WHERE ag.id_placement IS NOT NULL
|
||||||
AND ag.date_debut >= '2025-01-01';
|
AND ag.date_debut >= '2025-01-01';
|
||||||
|
|
||||||
@@ -198,7 +198,7 @@ SELECT
|
|||||||
(SELECT COUNT(*) FROM messages) AS nb_messages,
|
(SELECT COUNT(*) FROM messages) AS nb_messages,
|
||||||
(SELECT COUNT(*) FROM contrats) AS nb_contrats,
|
(SELECT COUNT(*) FROM contrats) AS nb_contrats,
|
||||||
(SELECT COUNT(*) FROM avenants_contrats) AS nb_avenants,
|
(SELECT COUNT(*) FROM avenants_contrats) AS nb_avenants,
|
||||||
(SELECT COUNT(*) FROM evenements_agenda) AS nb_evenements_agenda,
|
(SELECT COUNT(*) FROM absences_garde) AS nb_absences_garde,
|
||||||
(SELECT COUNT(*) FROM uploads) AS nb_uploads,
|
(SELECT COUNT(*) FROM uploads) AS nb_uploads,
|
||||||
(SELECT COUNT(*) FROM notifications) AS nb_notifications,
|
(SELECT COUNT(*) FROM notifications) AS nb_notifications,
|
||||||
(SELECT COUNT(*) FROM validations) AS nb_validations;
|
(SELECT COUNT(*) FROM validations) AS nb_validations;
|
||||||
|
|||||||
@@ -572,7 +572,7 @@ POST /repos/jmartin/petitspas/pulls/{index}/merge
|
|||||||
|
|
||||||
### 32. Module Absences + Cartes (séparation back / collecte)
|
### 32. Module Absences + Cartes (séparation back / collecte)
|
||||||
|
|
||||||
**Décision** : ✅ **Back `evenements_agenda` = vérité métier** ; **Cartes = file d’attention / collecte** (plugin isolé). Types SYSTEM (absence, congé, arrêt) indéboulonnables ; types OPTIONNELS (sondages…) plus tard. Annulation = DELETE. `expire_at` dès V1.
|
**Décision** : ✅ **Back `absences_garde` = vérité métier** ; **Cartes = file d’attention / collecte** (plugin isolé). Types SYSTEM (absence, congé, arrêt) indéboulonnables ; types OPTIONNELS (sondages…) plus tard. Annulation = DELETE. `expire_at` dès V1.
|
||||||
|
|
||||||
**Justification** :
|
**Justification** :
|
||||||
- Premier vrai module d’interaction multi-acteurs
|
- Premier vrai module d’interaction multi-acteurs
|
||||||
@@ -615,7 +615,7 @@ POST /repos/jmartin/petitspas/pulls/{index}/merge
|
|||||||
| 25/11/2025 | 1.0 | Création du document - Toutes les décisions initiales |
|
| 25/11/2025 | 1.0 | Création du document - Toutes les décisions initiales |
|
||||||
| 09/02/2026 | 1.1 | Configuration initiale : un seul panneau Paramètres (3 sections) dans le dashboard, plus de Setup Wizard dédié ; navigation bloquée jusqu'à sauvegarde |
|
| 09/02/2026 | 1.1 | Configuration initiale : un seul panneau Paramètres (3 sections) dans le dashboard, plus de Setup Wizard dédié ; navigation bloquée jusqu'à sauvegarde |
|
||||||
| 16/06/2026 | 1.2 | Décision 5bis — familles recomposées, contournement v1.0.0 ; lien doc [28](./28_EVOLUTION-FAMILLE-ET-RESPONSABLES.md) |
|
| 16/06/2026 | 1.2 | Décision 5bis — familles recomposées, contournement v1.0.0 ; lien doc [28](./28_EVOLUTION-FAMILLE-ET-RESPONSABLES.md) |
|
||||||
| 24/09/2026 | 1.4 | Décision 32 — Absences (`evenements_agenda`) ≠ Cartes ; Epic C recentré ; drop `evenements` |
|
| 24/09/2026 | 1.4 | Décision 32 — Absences (`absences_garde`) ≠ Cartes ; Epic C recentré ; drop `evenements` |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -98,13 +98,13 @@ Liste des enfants / foyers pour l’AM + contexte courant (symétrique A3).
|
|||||||
|
|
||||||
## Epic C — Absences + Cartes (file d’attention)
|
## Epic C — Absences + Cartes (file d’attention)
|
||||||
|
|
||||||
**Séparation :** back **`evenements_agenda`** = vérité métier (périodes / placement) ; module **Cartes** = collecte / bulles / workflow. Annulation = DELETE. `expire_at` dès le modèle.
|
**Séparation :** back **`absences_garde`** = vérité métier (périodes / placement) ; module **Cartes** = collecte / bulles / workflow. Annulation = DELETE. `expire_at` dès le modèle.
|
||||||
|
|
||||||
### Back (ordre)
|
### Back (ordre)
|
||||||
|
|
||||||
| Étape | Contenu |
|
| Étape | Contenu |
|
||||||
|-------|---------|
|
|-------|---------|
|
||||||
| BDD | Table `evenements_agenda` + drop `evenements` |
|
| BDD | Table `absences_garde` + drop `evenements` |
|
||||||
| API | CRUD + **GET liste** (`placementId` \| tous les placements du user) |
|
| API | CRUD + **GET liste** (`placementId` \| tous les placements du user) |
|
||||||
| Cartes SYSTEM | Module `cards/` types S1–S3 (sans sondages V1) |
|
| Cartes SYSTEM | Module `cards/` types S1–S3 (sans sondages V1) |
|
||||||
| Realtime | WS/SSE bulles → **SSE** `GET /cards/stream` (#195) |
|
| Realtime | WS/SSE bulles → **SSE** `GET /cards/stream` (#195) |
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ Bandeau : **TdB** · **Agenda** · **Contrat** · menu user (recherche AM, param
|
|||||||
| Maladie AM | AM | Parent **ack** (« bien reçu ») ; **aucun** doc médical |
|
| Maladie AM | AM | Parent **ack** (« bien reçu ») ; **aucun** doc médical |
|
||||||
| Sortie / sondage | — | **Plus tard** (types optionnels) |
|
| Sortie / sondage | — | **Plus tard** (types optionnels) |
|
||||||
|
|
||||||
**Stockage :** table `evenements_agenda` (1 ligne = période, `id_placement`, `expire_at`). Les **cartes** collectent ; elles ne sont pas la source de vérité. Annulation = DELETE.
|
**Stockage :** table `absences_garde` (1 ligne = période, `id_placement`, `expire_at`). Les **cartes** collectent ; elles ne sont pas la source de vérité. Annulation = DELETE.
|
||||||
|
|
||||||
**Péremption cartes :** mémoire courte (`retention_days` / `purge_at`) — pas un historique de vie (≠ messagerie).
|
**Péremption cartes :** mémoire courte (`retention_days` / `purge_at`) — pas un historique de vie (≠ messagerie).
|
||||||
|
|
||||||
|
|||||||
@@ -39,15 +39,13 @@ class CoupleMembre {
|
|||||||
class CoupleGarde {
|
class CoupleGarde {
|
||||||
final String id;
|
final String id;
|
||||||
final CoupleMembre enfant;
|
final CoupleMembre enfant;
|
||||||
final CoupleMembre? am;
|
final CoupleMembre am;
|
||||||
final List<CoupleMembre> parents;
|
|
||||||
final bool courant;
|
final bool courant;
|
||||||
|
|
||||||
const CoupleGarde({
|
const CoupleGarde({
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.enfant,
|
required this.enfant,
|
||||||
this.am,
|
required this.am,
|
||||||
this.parents = const [],
|
|
||||||
this.courant = false,
|
this.courant = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -57,15 +55,9 @@ class CoupleGarde {
|
|||||||
enfant: CoupleMembre.fromJson(
|
enfant: CoupleMembre.fromJson(
|
||||||
Map<String, dynamic>.from(json['enfant'] ?? const {}),
|
Map<String, dynamic>.from(json['enfant'] ?? const {}),
|
||||||
),
|
),
|
||||||
am: json['am'] != null
|
am: CoupleMembre.fromJson(
|
||||||
? CoupleMembre.fromJson(Map<String, dynamic>.from(json['am']))
|
Map<String, dynamic>.from(json['am'] ?? const {}),
|
||||||
: null,
|
),
|
||||||
parents: json['parents'] != null
|
|
||||||
? (json['parents'] as List)
|
|
||||||
.whereType<Map>()
|
|
||||||
.map((e) => CoupleMembre.fromJson(Map<String, dynamic>.from(e)))
|
|
||||||
.toList()
|
|
||||||
: const [],
|
|
||||||
courant: json['courant'] == true,
|
courant: json['courant'] == true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -75,7 +67,6 @@ class CoupleGarde {
|
|||||||
id: id,
|
id: id,
|
||||||
enfant: enfant,
|
enfant: enfant,
|
||||||
am: am,
|
am: am,
|
||||||
parents: parents,
|
|
||||||
courant: courant ?? this.courant,
|
courant: courant ?? this.courant,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:p_tits_pas/models/couple_garde.dart';
|
|
||||||
import 'package:p_tits_pas/models/user.dart';
|
import 'package:p_tits_pas/models/user.dart';
|
||||||
import 'package:p_tits_pas/services/auth_service.dart';
|
import 'package:p_tits_pas/services/auth_service.dart';
|
||||||
import 'package:p_tits_pas/services/couple_garde_service.dart';
|
|
||||||
import 'package:p_tits_pas/widgets/quotidien/couple_selector_bandeau.dart';
|
|
||||||
import 'package:p_tits_pas/widgets/quotidien/quotidien_shell.dart';
|
import 'package:p_tits_pas/widgets/quotidien/quotidien_shell.dart';
|
||||||
import 'package:p_tits_pas/widgets/quotidien/quotidien_theme.dart';
|
import 'package:p_tits_pas/widgets/quotidien/quotidien_theme.dart';
|
||||||
import 'package:p_tits_pas/screens/home/parent_screen/agenda_absences_stub.dart';
|
|
||||||
|
|
||||||
/// Dashboard assistante maternelle – coquille 3 colonnes quotidien (#169).
|
/// Dashboard assistante maternelle – coquille 3 colonnes quotidien (#169).
|
||||||
/// Colonne gauche : sélecteur de couple enfant–parent(s) (#170).
|
/// Colonne gauche : sélecteur de couple enfant–parent(s) (à venir #170).
|
||||||
/// Métier cartes / blog / messagerie : tickets C/D/E.
|
/// Métier cartes / blog / messagerie : tickets C/D/E.
|
||||||
class AmDashboardScreen extends StatefulWidget {
|
class AmDashboardScreen extends StatefulWidget {
|
||||||
const AmDashboardScreen({super.key});
|
const AmDashboardScreen({super.key});
|
||||||
@@ -22,16 +18,10 @@ class _AmDashboardScreenState extends State<AmDashboardScreen> {
|
|||||||
QuotidienNavSection _section = QuotidienNavSection.liaison;
|
QuotidienNavSection _section = QuotidienNavSection.liaison;
|
||||||
AppUser? _user;
|
AppUser? _user;
|
||||||
|
|
||||||
List<CoupleGarde> _couples = const [];
|
|
||||||
String? _selectedCoupleId;
|
|
||||||
bool _couplesLoading = true;
|
|
||||||
String? _couplesError;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_loadUser();
|
_loadUser();
|
||||||
_loadCouples();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadUser() async {
|
Future<void> _loadUser() async {
|
||||||
@@ -39,51 +29,6 @@ class _AmDashboardScreenState extends State<AmDashboardScreen> {
|
|||||||
if (mounted) setState(() => _user = user);
|
if (mounted) setState(() => _user = user);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadCouples() async {
|
|
||||||
setState(() {
|
|
||||||
_couplesLoading = true;
|
|
||||||
_couplesError = null;
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
final res = await CoupleGardeService.getAmCouplesGarde();
|
|
||||||
if (!mounted) return;
|
|
||||||
setState(() {
|
|
||||||
_couples = res.couples;
|
|
||||||
_selectedCoupleId = res.coupleCourant?.id;
|
|
||||||
_couplesLoading = false;
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
if (!mounted) return;
|
|
||||||
setState(() {
|
|
||||||
_couplesError = e.toString().replaceFirst('Exception: ', '');
|
|
||||||
_couplesLoading = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _selectCouple(CoupleGarde couple) async {
|
|
||||||
if (couple.id == _selectedCoupleId) return;
|
|
||||||
setState(() => _selectedCoupleId = couple.id);
|
|
||||||
try {
|
|
||||||
final res = await CoupleGardeService.definirAmCoupleCourant(couple.id);
|
|
||||||
if (!mounted) return;
|
|
||||||
setState(() {
|
|
||||||
_couples = res.couples;
|
|
||||||
_selectedCoupleId = res.coupleCourant?.id ?? couple.id;
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
if (!mounted) return;
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text(
|
|
||||||
"Impossible de changer d'enfant : "
|
|
||||||
'${e.toString().replaceFirst('Exception: ', '')}',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String get _displayName {
|
String get _displayName {
|
||||||
final n = _user?.fullName.trim() ?? '';
|
final n = _user?.fullName.trim() ?? '';
|
||||||
if (n.isNotEmpty) return n;
|
if (n.isNotEmpty) return n;
|
||||||
@@ -109,13 +54,11 @@ class _AmDashboardScreenState extends State<AmDashboardScreen> {
|
|||||||
onSettingsTap: () => _soon('Paramètres'),
|
onSettingsTap: () => _soon('Paramètres'),
|
||||||
// L'AM n'a pas de bouton "Recherche AM" dans le bandeau
|
// L'AM n'a pas de bouton "Recherche AM" dans le bandeau
|
||||||
onSearchAmTap: null,
|
onSearchAmTap: null,
|
||||||
leftColumn: _LeftColumn(
|
leftColumn: const QuotidienColumnPlaceholder(
|
||||||
couples: _couples,
|
title: 'Cartes',
|
||||||
selectedCoupleId: _selectedCoupleId,
|
subtitle:
|
||||||
loading: _couplesLoading,
|
'Couple enfant–parent(s) et flux de cartes\n(à brancher — tickets #170 / #174).',
|
||||||
error: _couplesError,
|
icon: Icons.style_outlined,
|
||||||
onRetry: _loadCouples,
|
|
||||||
onCoupleSelected: _selectCouple,
|
|
||||||
),
|
),
|
||||||
centerColumn: const QuotidienColumnPlaceholder(
|
centerColumn: const QuotidienColumnPlaceholder(
|
||||||
title: 'Blog',
|
title: 'Blog',
|
||||||
@@ -129,7 +72,10 @@ class _AmDashboardScreenState extends State<AmDashboardScreen> {
|
|||||||
'Mess. Parents · Mess. RPE\n(à brancher — ticket #185).',
|
'Mess. Parents · Mess. RPE\n(à brancher — ticket #185).',
|
||||||
icon: Icons.chat_bubble_outline,
|
icon: Icons.chat_bubble_outline,
|
||||||
),
|
),
|
||||||
agendaBody: AgendaAbsencesStub(placementId: _selectedCoupleId),
|
agendaBody: const QuotidienStubPage(
|
||||||
|
title: 'Agenda',
|
||||||
|
message: 'Agenda — contenu à venir (stub #187).',
|
||||||
|
),
|
||||||
contratBody: const QuotidienStubPage(
|
contratBody: const QuotidienStubPage(
|
||||||
title: 'Contrat',
|
title: 'Contrat',
|
||||||
message: 'Contrat — contenu à venir (stub #187).',
|
message: 'Contrat — contenu à venir (stub #187).',
|
||||||
@@ -138,51 +84,3 @@ class _AmDashboardScreenState extends State<AmDashboardScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _LeftColumn extends StatelessWidget {
|
|
||||||
final List<CoupleGarde> couples;
|
|
||||||
final String? selectedCoupleId;
|
|
||||||
final bool loading;
|
|
||||||
final String? error;
|
|
||||||
final VoidCallback onRetry;
|
|
||||||
final ValueChanged<CoupleGarde> onCoupleSelected;
|
|
||||||
|
|
||||||
const _LeftColumn({
|
|
||||||
required this.couples,
|
|
||||||
required this.selectedCoupleId,
|
|
||||||
required this.loading,
|
|
||||||
required this.error,
|
|
||||||
required this.onRetry,
|
|
||||||
required this.onCoupleSelected,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.all(14),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
||||||
children: [
|
|
||||||
CoupleSelectorBandeau(
|
|
||||||
mode: CoupleBandeauMode.assistanteMaternelle,
|
|
||||||
couples: couples,
|
|
||||||
selectedCoupleId: selectedCoupleId,
|
|
||||||
loading: loading,
|
|
||||||
errorMessage: error,
|
|
||||||
onRetry: onRetry,
|
|
||||||
onCoupleSelected: onCoupleSelected,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 14),
|
|
||||||
const Expanded(
|
|
||||||
child: QuotidienColumnPlaceholder(
|
|
||||||
title: 'Cartes',
|
|
||||||
subtitle:
|
|
||||||
'Absences, congés AM, sorties à valider\n(à brancher — ticket #174).',
|
|
||||||
icon: Icons.style_outlined,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class AbsencesGardeService {
|
|||||||
final headers = token != null ? ApiConfig.authHeaders(token) : ApiConfig.headers;
|
final headers = token != null ? ApiConfig.authHeaders(token) : ApiConfig.headers;
|
||||||
|
|
||||||
final uri = Uri.parse(ApiConfig.baseUrl +
|
final uri = Uri.parse(ApiConfig.baseUrl +
|
||||||
'/evenements-agenda' +
|
'/absences-garde' +
|
||||||
(placementId != null ? '?placementId=$placementId' : ''));
|
(placementId != null ? '?placementId=$placementId' : ''));
|
||||||
|
|
||||||
final res = await http.get(uri, headers: headers);
|
final res = await http.get(uri, headers: headers);
|
||||||
@@ -33,7 +33,7 @@ class AbsencesGardeService {
|
|||||||
final token = await TokenService.getToken();
|
final token = await TokenService.getToken();
|
||||||
final headers = token != null ? ApiConfig.authHeaders(token) : ApiConfig.headers;
|
final headers = token != null ? ApiConfig.authHeaders(token) : ApiConfig.headers;
|
||||||
|
|
||||||
final uri = Uri.parse('${ApiConfig.baseUrl}/evenements-agenda');
|
final uri = Uri.parse('${ApiConfig.baseUrl}/absences-garde');
|
||||||
final res = await http.post(
|
final res = await http.post(
|
||||||
uri,
|
uri,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
@@ -62,7 +62,7 @@ class AbsencesGardeService {
|
|||||||
final token = await TokenService.getToken();
|
final token = await TokenService.getToken();
|
||||||
final headers = token != null ? ApiConfig.authHeaders(token) : ApiConfig.headers;
|
final headers = token != null ? ApiConfig.authHeaders(token) : ApiConfig.headers;
|
||||||
|
|
||||||
final uri = Uri.parse('${ApiConfig.baseUrl}/evenements-agenda/$id');
|
final uri = Uri.parse('${ApiConfig.baseUrl}/absences-garde/$id');
|
||||||
final Map<String, dynamic> body = {};
|
final Map<String, dynamic> body = {};
|
||||||
if (dateDebut != null) body['date_debut'] = dateDebut;
|
if (dateDebut != null) body['date_debut'] = dateDebut;
|
||||||
if (dateFin != null) body['date_fin'] = dateFin;
|
if (dateFin != null) body['date_fin'] = dateFin;
|
||||||
@@ -85,7 +85,7 @@ class AbsencesGardeService {
|
|||||||
final token = await TokenService.getToken();
|
final token = await TokenService.getToken();
|
||||||
final headers = token != null ? ApiConfig.authHeaders(token) : ApiConfig.headers;
|
final headers = token != null ? ApiConfig.authHeaders(token) : ApiConfig.headers;
|
||||||
|
|
||||||
final uri = Uri.parse('${ApiConfig.baseUrl}/evenements-agenda/$id');
|
final uri = Uri.parse('${ApiConfig.baseUrl}/absences-garde/$id');
|
||||||
final res = await http.delete(uri, headers: headers);
|
final res = await http.delete(uri, headers: headers);
|
||||||
if (res.statusCode != 204) {
|
if (res.statusCode != 204) {
|
||||||
throw Exception("Erreur de suppression d'absence : ${res.statusCode}");
|
throw Exception("Erreur de suppression d'absence : ${res.statusCode}");
|
||||||
|
|||||||
@@ -67,11 +67,7 @@ class ApiConfig {
|
|||||||
static const String parentsCoupleGardeCourant =
|
static const String parentsCoupleGardeCourant =
|
||||||
'/parents/me/couples-garde/courant';
|
'/parents/me/couples-garde/courant';
|
||||||
static const String assistantesMaternelles = '/assistantes-maternelles';
|
static const String assistantesMaternelles = '/assistantes-maternelles';
|
||||||
/// Couples de garde de l'AM connectée (#170 / #171).
|
/// Création dossier AM actif par le staff (#156) — body type register AM.
|
||||||
static const String assistantesMaternellesCouplesGarde =
|
|
||||||
'/assistantes-maternelles/me/couples-garde';
|
|
||||||
static const String assistantesMaternellesCoupleGardeCourant =
|
|
||||||
'/assistantes-maternelles/me/couples-garde/courant';
|
|
||||||
static const String assistantesMaternellesDossier =
|
static const String assistantesMaternellesDossier =
|
||||||
'/assistantes-maternelles/dossier';
|
'/assistantes-maternelles/dossier';
|
||||||
static const String enfants = '/enfants';
|
static const String enfants = '/enfants';
|
||||||
|
|||||||
@@ -73,45 +73,4 @@ class CoupleGardeService {
|
|||||||
Map<String, dynamic>.from(decoded as Map),
|
Map<String, dynamic>.from(decoded as Map),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Liste les couples de garde et le couple courant de l'AM connectée.
|
|
||||||
static Future<CouplesGardeResponse> getAmCouplesGarde() async {
|
|
||||||
final response = await http.get(
|
|
||||||
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.assistantesMaternellesCouplesGarde}'),
|
|
||||||
headers: await _headers(),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (response.statusCode != 200) {
|
|
||||||
throw Exception(
|
|
||||||
_extractError(response.body, 'Erreur chargement des couples de garde (AM)'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final decoded = jsonDecode(response.body);
|
|
||||||
return CouplesGardeResponse.fromJson(
|
|
||||||
Map<String, dynamic>.from(decoded as Map),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Persiste le couple courant (AM) et renvoie la liste à jour.
|
|
||||||
static Future<CouplesGardeResponse> definirAmCoupleCourant(
|
|
||||||
String coupleId,
|
|
||||||
) async {
|
|
||||||
final response = await http.put(
|
|
||||||
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.assistantesMaternellesCoupleGardeCourant}'),
|
|
||||||
headers: await _headers(),
|
|
||||||
body: jsonEncode({'couple_id': coupleId}),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (response.statusCode != 200) {
|
|
||||||
throw Exception(
|
|
||||||
_extractError(response.body, 'Erreur sélection du couple de garde (AM)'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final decoded = jsonDecode(response.body);
|
|
||||||
return CouplesGardeResponse.fromJson(
|
|
||||||
Map<String, dynamic>.from(decoded as Map),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class CoupleSelectorBandeau extends StatelessWidget {
|
|||||||
|
|
||||||
CoupleGarde? get _selected {
|
CoupleGarde? get _selected {
|
||||||
if (couples.isEmpty) return null;
|
if (couples.isEmpty) return null;
|
||||||
if (selectedCoupleId != null) {
|
if (selectedCoupleId != null) {
|
||||||
for (final c in couples) {
|
for (final c in couples) {
|
||||||
if (c.id == selectedCoupleId) return c;
|
if (c.id == selectedCoupleId) return c;
|
||||||
}
|
}
|
||||||
@@ -133,47 +133,8 @@ class _CoupleCard extends StatelessWidget {
|
|||||||
required this.colorIndex,
|
required this.colorIndex,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Libellé parents côté AM : « Sophie » ou « Thomas et Claire ».
|
|
||||||
static String _parentsLabel(List<CoupleMembre> parents) {
|
|
||||||
if (parents.isEmpty) return 'Parents';
|
|
||||||
String prenomOf(CoupleMembre p) {
|
|
||||||
final prenom = (p.prenom ?? '').trim();
|
|
||||||
if (prenom.isNotEmpty) return prenom;
|
|
||||||
return p.displayName(fallback: 'Parent');
|
|
||||||
}
|
|
||||||
if (parents.length == 1) return prenomOf(parents.first);
|
|
||||||
return '${prenomOf(parents[0])} et ${prenomOf(parents[1])}';
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Parent mode: enfant | AM (photo + prénom)
|
|
||||||
// AM mode: enfant | parent(s) — texte seul, pas de vignette parent
|
|
||||||
final isParentMode = mode == CoupleBandeauMode.parent;
|
|
||||||
|
|
||||||
Widget amOrParentsWidget;
|
|
||||||
|
|
||||||
if (isParentMode) {
|
|
||||||
amOrParentsWidget = _MembreTile(
|
|
||||||
photoUrl: couple.am?.photoUrl,
|
|
||||||
name: (couple.am?.prenom != null && couple.am!.prenom!.isNotEmpty)
|
|
||||||
? couple.am!.prenom!
|
|
||||||
: (couple.am?.displayName(fallback: 'Nounou') ?? 'Nounou'),
|
|
||||||
fallbackIcon: Icons.volunteer_activism,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
amOrParentsWidget = Text(
|
|
||||||
_parentsLabel(couple.parents),
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: GoogleFonts.merienda(
|
|
||||||
fontSize: 22,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: QuotidienTheme.ink,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
height: 90,
|
height: 90,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@@ -210,7 +171,19 @@ class _CoupleCard extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(left: 12),
|
padding: const EdgeInsets.only(left: 12),
|
||||||
child: amOrParentsWidget,
|
child: _MembreTile(
|
||||||
|
photoUrl: couple.am.photoUrl,
|
||||||
|
name: (couple.am.prenom != null && couple.am.prenom!.isNotEmpty)
|
||||||
|
? couple.am.prenom!
|
||||||
|
: couple.am.displayName(
|
||||||
|
fallback: mode == CoupleBandeauMode.parent
|
||||||
|
? 'Nounou'
|
||||||
|
: 'Parent',
|
||||||
|
),
|
||||||
|
fallbackIcon: mode == CoupleBandeauMode.parent
|
||||||
|
? Icons.volunteer_activism
|
||||||
|
: Icons.person_outline,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
|
|||||||
Reference in New Issue
Block a user