/companies/{id}/driversAjout d'un endpoint REST pour récupérer la liste des chauffeurs d'une compagnie spécifique avec support de la pagination.
Fichier: src/application/use-cases/company/find-drivers-by-company.use-case.ts
export class FindDriversByCompanyUseCase {
async execute(companyId: number, page: number = 1, limit: number = 10) {
return await this.companyRepository.findDriversByCompanyId(companyId, page, limit);
}
}
Responsabilités:
Fichier: src/infrastructure/repositories/company.repository.ts
async findDriversByCompanyId(companyId: number, page: number = 1, limit: number = 10) {
const skip = (page - 1) * limit;
const [drivers, total] = await Promise.all([
this.prisma.user.findMany({
where: {
companyId,
role: 'DRIVER'
},
include: {
company: true,
managedCompany: true,
driver: {
include: {
vehicules: true
}
}
},
skip,
take: limit,
orderBy: { createdAt: 'desc' }
}),
this.prisma.user.count({
where: {
companyId,
role: 'DRIVER'
}
})
]);
return {
data: drivers,
total,
page,
limit,
totalPages: Math.ceil(total / limit)
};
}
Responsabilités:
companyId et role: 'DRIVER'Fichier: src/presentation/controllers/company.controller.ts
@Get(':id/drivers')
@ApiOperation({ summary: 'Récupérer les chauffeurs d\'une compagnie' })
@ApiResponse({ status: 200, description: 'Liste des chauffeurs récupérée avec succès' })
@ApiResponse({ status: 404, description: 'Compagnie non trouvée' })
@Roles(UserRole.ADMIN, UserRole.MANAGER, UserRole.EMPLOYEE)
async getDrivers(
@Param('id') id: string,
@Query('page') page: string = '1',
@Query('limit') limit: string = '10'
) {
const companyId = parseInt(id, 10);
const pageNum = parseInt(page, 10);
const limitNum = parseInt(limit, 10);
// Vérifier que la compagnie existe
const company = await this.findCompanyByIdUseCase.execute(companyId);
if (!company) {
throw new NotFoundException('Compagnie non trouvée');
}
const result = await this.findDriversByCompanyUseCase.execute(companyId, pageNum, limitNum);
return {
success: true,
message: 'Chauffeurs récupérés avec succès',
data: result
};
}
Responsabilités:
Fichier: src/app.module.ts
// Import ajouté
import { FindDriversByCompanyUseCase } from './application/use-cases/company/find-drivers-by-company.use-case';
// Provider ajouté
providers: [
// ... autres providers
FindDriversByCompanyUseCase,
// ...
]
Fichier: app_transport_front/src/services/CompanyService.ts
async getCompanyDrivers(id: number, page: number = 1, limit: number = 10): Promise<{
drivers: any[],
pagination: { total: number, page: number, limit: number, totalPages: number }
}> {
const response = await authenticatedFetch(`${API_URL}/companies/${id}/drivers?page=${page}&limit=${limit}`);
const result = await response.json();
return {
drivers: result.data?.data || [],
pagination: {
total: result.data?.total || 0,
page: result.data?.page || 1,
limit: result.data?.limit || 10,
totalPages: result.data?.totalPages || 1
}
};
}
Fichier: app_transport_front/src/components/CompanyDriversList.vue
Fonctionnalités:
GET /companies/{id}/drivers
id (number) - ID de la compagniepage (number, optionnel) - Numéro de page (défaut: 1)limit (number, optionnel) - Nombre d'éléments par page (défaut: 10)ADMIN, MANAGER, EMPLOYEE{
"success": true,
"message": "Chauffeurs récupérés avec succès",
"data": {
"data": [
{
"id": 1,
"firstName": "Jean",
"lastName": "Dupont",
"email": "jean.dupont@example.com",
"telephone": "0123456789",
"role": "DRIVER",
"companyId": 1,
"company": { ... },
"driver": {
"vehicules": [
{
"id": 1,
"model": "Mercedes Sprinter",
"immatriculation": "AB-123-CD"
}
]
}
}
],
"total": 25,
"page": 1,
"limit": 10,
"totalPages": 3
}
}
Fichier: test/e2e/company-drivers.e2e-spec.ts
Scénarios testés:
Fichier: test-endpoint.js
node test-endpoint.js
Fichier: docs/endpoints/companies-drivers.md
Contenu:
/companies/{id}/driverscd node_app
npm run start:dev
cd app_transport_front
npm run dev
# Test manuel
node test-endpoint.js
# Tests E2E
npm run test:e2e -- company-drivers.e2e-spec.ts
L'endpoint est maintenant disponible et peut être utilisé par :
CompanyDriversList.vue pour afficher les chauffeurscompanyId et role recommandés