Compare commits
3 Commits
e402d75610
...
223bce143b
| Author | SHA1 | Date | |
|---|---|---|---|
| 223bce143b | |||
| a8ca887f3d | |||
| 7c06fc9c00 |
7
.gitignore
vendored
7
.gitignore
vendored
@ -55,3 +55,10 @@ pids
|
|||||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
|
||||||
|
# Tests bdd
|
||||||
|
.vscode/
|
||||||
|
BDD.sql
|
||||||
|
migrations/
|
||||||
|
src/seed/
|
||||||
|
|||||||
38
src/routes/enfants/dto/enfants_response.dto.ts
Normal file
38
src/routes/enfants/dto/enfants_response.dto.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import { ApiProperty } from "@nestjs/swagger";
|
||||||
|
import { GenreType, StatutEnfantType } from "src/entities/children.entity";
|
||||||
|
|
||||||
|
export class EnfantResponseDto {
|
||||||
|
@ApiProperty({ example: 'UUID-enfant' })
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@ApiProperty({ enum: StatutEnfantType })
|
||||||
|
status: StatutEnfantType;
|
||||||
|
|
||||||
|
@ApiProperty({ example: 'Georges', required: false })
|
||||||
|
first_name?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ example: 'Dupont', required: false })
|
||||||
|
last_name?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ enum: GenreType, required: false })
|
||||||
|
gender?: GenreType;
|
||||||
|
|
||||||
|
@ApiProperty({ example: '2018-06-24', required: false })
|
||||||
|
birth_date?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ example: '2024-12-24', required: false })
|
||||||
|
due_date?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ example: 'https://monimage.com/photo.jpg', required: false })
|
||||||
|
photo_url?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ example: false })
|
||||||
|
consent_photo: boolean;
|
||||||
|
|
||||||
|
@ApiProperty({ example: false })
|
||||||
|
is_multiple: boolean;
|
||||||
|
|
||||||
|
@ApiProperty({ example: 'UUID-parent' })
|
||||||
|
parent_id: string;
|
||||||
|
|
||||||
|
}
|
||||||
@ -6,6 +6,8 @@ import { Roles } from 'src/common/decorators/roles.decorator';
|
|||||||
import { RoleType } from 'src/entities/users.entity';
|
import { RoleType } from 'src/entities/users.entity';
|
||||||
import { Children } from 'src/entities/children.entity';
|
import { Children } from 'src/entities/children.entity';
|
||||||
import { CreateEnfantsDto } from './dto/create_enfants.dto';
|
import { CreateEnfantsDto } from './dto/create_enfants.dto';
|
||||||
|
import { EnfantResponseDto } from './dto/enfants_response.dto';
|
||||||
|
import { mapEnfantsToResponseDto, mapEnfantToResponseDto } from './enfants.mapper';
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@ApiTags('Enfants')
|
@ApiTags('Enfants')
|
||||||
@ -13,43 +15,55 @@ import { CreateEnfantsDto } from './dto/create_enfants.dto';
|
|||||||
@Controller('enfants')
|
@Controller('enfants')
|
||||||
export class EnfantsController {
|
export class EnfantsController {
|
||||||
constructor(private readonly enfantsService: EnfantsService) { }
|
constructor(private readonly enfantsService: EnfantsService) { }
|
||||||
|
// Inscrire un enfant
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Inscrire un enfant' })
|
@ApiOperation({ summary: 'Inscrire un enfant' })
|
||||||
@ApiResponse({ status: 201, type: Children, description: 'L\'enfant a été inscrit avec succès.' })
|
@ApiResponse({ status: 201, type: EnfantResponseDto, description: 'L\'enfant a été inscrit avec succès.' })
|
||||||
@Roles(RoleType.PARENT, RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
@Roles(RoleType.PARENT, RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
||||||
async create(@Body() dto: CreateEnfantsDto): Promise<Children> {
|
async create(@Body() dto: CreateEnfantsDto): Promise<EnfantResponseDto> {
|
||||||
return this.enfantsService.create(dto);
|
const enfant = await this.enfantsService.create(dto);
|
||||||
}
|
|
||||||
|
// Mapper l'entité enfant vers le DTO de réponse
|
||||||
|
return mapEnfantToResponseDto(enfant);
|
||||||
|
}
|
||||||
|
|
||||||
// Récupérer tous les enfants avec leurs liens parents
|
// Récupérer tous les enfants avec leurs liens parents
|
||||||
@ApiOperation({ summary: 'Récupérer tous les enfants avec leurs liens parents' })
|
@ApiOperation({ summary: 'Récupérer tous les enfants avec leurs liens parents' })
|
||||||
@ApiResponse({ status: 200, type: [Children], description: 'Liste de tous les enfants avec leurs liens parents.' })
|
@ApiResponse({ status: 200, type: [EnfantResponseDto], description: 'Liste de tous les enfants avec leurs liens parents.' })
|
||||||
@Get()
|
@Get()
|
||||||
@Roles(RoleType.GESTIONNAIRE, RoleType.SUPER_ADMIN)
|
@Roles(RoleType.GESTIONNAIRE, RoleType.SUPER_ADMIN)
|
||||||
async findAll(): Promise<Children[]> {
|
async findAll(): Promise<EnfantResponseDto[]> {
|
||||||
return this.enfantsService.findAll();
|
const enfants = await this.enfantsService.findAll();
|
||||||
|
|
||||||
|
// Mapper les entités enfants vers les DTO de réponse
|
||||||
|
return mapEnfantsToResponseDto(enfants);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Récupérer un enfant par son ID
|
// Récupérer un enfant par son ID
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
@ApiOperation({ summary: 'Récupérer un enfant par son ID' })
|
@ApiOperation({ summary: 'Récupérer un enfant par son ID' })
|
||||||
@ApiResponse({ status: 200, type: Children, description: 'Détails de l\'enfant avec ses liens parents.' })
|
@ApiResponse({ status: 200, type: EnfantResponseDto, description: 'Détails de l\'enfant avec ses liens parents.' })
|
||||||
@Roles(RoleType.GESTIONNAIRE, RoleType.SUPER_ADMIN, RoleType.PARENT)
|
@Roles(RoleType.GESTIONNAIRE, RoleType.SUPER_ADMIN, RoleType.PARENT)
|
||||||
async findOne(@Param('id', new ParseUUIDPipe()) id: string): Promise<Children> {
|
async findOne(@Param('id', new ParseUUIDPipe()) id: string): Promise<EnfantResponseDto> {
|
||||||
return this.enfantsService.findOne(id);
|
const enfant = await this.enfantsService.findOne(id);
|
||||||
|
|
||||||
|
// Mapper l'entité enfant vers le DTO de réponse
|
||||||
|
return mapEnfantToResponseDto(enfant);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mettre à jour un enfant
|
// Mettre à jour un enfant
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
@ApiOperation({ summary: 'Mettre à jour un enfant' })
|
@ApiOperation({ summary: 'Mettre à jour un enfant' })
|
||||||
@ApiResponse({ status: 200, type: Children, description: 'L\'enfant a été mis à jour avec succès.' })
|
@ApiResponse({ status: 200, type: EnfantResponseDto, description: 'L\'enfant a été mis à jour avec succès.' })
|
||||||
@Roles(RoleType.GESTIONNAIRE, RoleType.SUPER_ADMIN)
|
@Roles(RoleType.GESTIONNAIRE, RoleType.SUPER_ADMIN)
|
||||||
async update(
|
async update(
|
||||||
@Param('id', new ParseUUIDPipe()) id: string,
|
@Param('id', new ParseUUIDPipe()) id: string,
|
||||||
@Body() dto: Partial<CreateEnfantsDto>,
|
@Body() dto: Partial<CreateEnfantsDto>,
|
||||||
): Promise<Children> {
|
): Promise<EnfantResponseDto> {
|
||||||
return this.enfantsService.update(id, dto);
|
const enfant = await this.enfantsService.update(id, dto);
|
||||||
|
|
||||||
|
// Mapper l'entité enfant vers le DTO de réponse
|
||||||
|
return mapEnfantToResponseDto(enfant);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supprimer un enfant
|
// Supprimer un enfant
|
||||||
|
|||||||
24
src/routes/enfants/enfants.mapper.ts
Normal file
24
src/routes/enfants/enfants.mapper.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { Children } from "src/entities/children.entity";
|
||||||
|
import { EnfantResponseDto } from "./dto/enfants_response.dto";
|
||||||
|
|
||||||
|
// Fonction pour mapper une entité Children vers EnfantResponseDto
|
||||||
|
export function mapEnfantToResponseDto(enfant: Children): EnfantResponseDto {
|
||||||
|
return {
|
||||||
|
id: enfant.id,
|
||||||
|
status: enfant.status,
|
||||||
|
first_name: enfant.first_name,
|
||||||
|
last_name: enfant.last_name,
|
||||||
|
gender: enfant.gender,
|
||||||
|
birth_date: enfant.birth_date?.toISOString(),
|
||||||
|
due_date: enfant.due_date?.toISOString(),
|
||||||
|
photo_url: enfant.photo_url,
|
||||||
|
consent_photo: enfant.consent_photo,
|
||||||
|
is_multiple: enfant.is_multiple,
|
||||||
|
parent_id: enfant.parentLinks?.[0]?.parentId ?? null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function mapEnfantsToResponseDto(enfants: Children[]): EnfantResponseDto[] {
|
||||||
|
return enfants.map(mapEnfantToResponseDto);
|
||||||
|
};
|
||||||
|
|
||||||
@ -3,17 +3,10 @@ import { EnfantsController } from './enfants.controller';
|
|||||||
import { EnfantsService } from './enfants.service';
|
import { EnfantsService } from './enfants.service';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { Children } from 'src/entities/children.entity';
|
import { Children } from 'src/entities/children.entity';
|
||||||
import { ParentsModule } from '../parents/parents.module';
|
|
||||||
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
|
||||||
import { Parents } from 'src/entities/parents.entity';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [TypeOrmModule.forFeature([Children])],
|
||||||
TypeOrmModule.forFeature([Children, ParentsChildren, Parents]),
|
|
||||||
ParentsModule,
|
|
||||||
],
|
|
||||||
controllers: [EnfantsController],
|
controllers: [EnfantsController],
|
||||||
providers: [EnfantsService],
|
providers: [EnfantsService],
|
||||||
exports: [EnfantsService],
|
|
||||||
})
|
})
|
||||||
export class EnfantsModule {}
|
export class EnfantsModule {}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user