|
|
@@ -20,6 +20,11 @@ import { UpdateCompanyDto } from '../../application/dto/update-company.dto';
|
|
|
import { FindAllCompaniesUseCase } from '../../application/use-cases/company/find-all-companies.use-case';
|
|
|
import { CompanyResponseDto } from 'src/application/dto/responses/company-response.dto';
|
|
|
import { CreateCompanyUseCase } from '../../application/use-cases/company/create-company.use-case';
|
|
|
+import { Roles } from '../decorators/roles.decorator';
|
|
|
+import { UserRole } from 'src/domain/entities/user.entity';
|
|
|
+import { FindCompanyByIdUseCase } from '../../application/use-cases/company/find-company-by-id.use-case';
|
|
|
+import { NotFoundException } from '@nestjs/common';
|
|
|
+import { FindUniqueCompanyByManagerUseCase } from 'src/application/use-cases/company/find-unique-company-by-manager.use-case';
|
|
|
|
|
|
@ApiTags('companies')
|
|
|
@Controller('companies')
|
|
|
@@ -28,6 +33,8 @@ export class CompanyController {
|
|
|
constructor(
|
|
|
private readonly findAllCompaniesUseCase: FindAllCompaniesUseCase,
|
|
|
private readonly createCompanyUseCase: CreateCompanyUseCase,
|
|
|
+ private readonly findCompanyByIdUseCase: FindCompanyByIdUseCase,
|
|
|
+ private readonly findCompanyByManager: FindUniqueCompanyByManagerUseCase,
|
|
|
) {}
|
|
|
|
|
|
@Post()
|
|
|
@@ -47,6 +54,7 @@ export class CompanyController {
|
|
|
}
|
|
|
|
|
|
@Get()
|
|
|
+ @Roles(UserRole.ADMIN)
|
|
|
@ApiOperation({ summary: 'Récupérer toutes les entreprises' })
|
|
|
@ApiResponse({
|
|
|
status: 200,
|
|
|
@@ -58,6 +66,7 @@ export class CompanyController {
|
|
|
}
|
|
|
|
|
|
@Get(':id')
|
|
|
+ @Roles(UserRole.ADMIN, UserRole.MANAGER, UserRole.USER)
|
|
|
@ApiOperation({ summary: 'Récupérer une entreprise par son ID' })
|
|
|
@ApiParam({ name: 'id', description: "ID de l'entreprise" })
|
|
|
@ApiResponse({
|
|
|
@@ -67,7 +76,49 @@ export class CompanyController {
|
|
|
})
|
|
|
@ApiResponse({ status: 404, description: 'Entreprise non trouvée' })
|
|
|
async findOne(@Param('id') id: string) {
|
|
|
- // TODO: Implement get company by id use case
|
|
|
+ try {
|
|
|
+ const company = await this.findCompanyByIdUseCase.execute(
|
|
|
+ parseInt(id, 10),
|
|
|
+ );
|
|
|
+
|
|
|
+ if (!company) {
|
|
|
+ throw new NotFoundException(`Entreprise avec l'ID ${id} non trouvée`);
|
|
|
+ }
|
|
|
+
|
|
|
+ return company;
|
|
|
+ } catch (error) {
|
|
|
+ if (error instanceof NotFoundException) {
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+ throw new NotFoundException(`Entreprise avec l'ID ${id} non trouvée`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Get('/manager/:id')
|
|
|
+ @Roles(UserRole.ADMIN, UserRole.MANAGER, UserRole.USER)
|
|
|
+ @ApiOperation({ summary: 'Récupérer une entreprise par son ID' })
|
|
|
+ @ApiParam({ name: 'id', description: 'ID de du manager' })
|
|
|
+ @ApiResponse({
|
|
|
+ status: 200,
|
|
|
+ description: "L'entreprise a été trouvée",
|
|
|
+ type: CompanyResponseDto,
|
|
|
+ })
|
|
|
+ @ApiResponse({ status: 404, description: 'Entreprise non trouvée' })
|
|
|
+ async findOneByManaderId(@Param('id') id: string) {
|
|
|
+ try {
|
|
|
+ const company = await this.findCompanyByManager.execute(parseInt(id, 10));
|
|
|
+
|
|
|
+ if (!company) {
|
|
|
+ throw new NotFoundException(`Entreprise avec l'ID ${id} non trouvée`);
|
|
|
+ }
|
|
|
+
|
|
|
+ return company;
|
|
|
+ } catch (error) {
|
|
|
+ if (error instanceof NotFoundException) {
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+ throw new NotFoundException(`Entreprise avec l'ID ${id} non trouvée`);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Put(':id')
|