| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 40 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { |
||
| 2 | Controller, |
||
| 3 | Inject, |
||
| 4 | UseGuards, |
||
| 5 | Get, |
||
| 6 | Param, |
||
| 7 | NotFoundException |
||
| 8 | } from '@nestjs/common'; |
||
| 9 | import {AuthGuard} from '@nestjs/passport'; |
||
| 10 | import {ApiTags, ApiBearerAuth, ApiOperation} from '@nestjs/swagger'; |
||
| 11 | import {CustomerView} from 'src/Application/Customer/View/CustomerView'; |
||
| 12 | import {GetCustomerByIdQuery} from 'src/Application/Customer/Query/GetCustomerByIdQuery'; |
||
| 13 | import {IQueryBus} from 'src/Application/IQueryBus'; |
||
| 14 | import {IdDTO} from 'src/Infrastructure/Common/DTO/IdDTO'; |
||
| 15 | import {UserRole} from 'src/Domain/HumanResource/User/User.entity'; |
||
| 16 | import {Roles} from 'src/Infrastructure/HumanResource/User/Decorator/Roles'; |
||
| 17 | import {RolesGuard} from 'src/Infrastructure/HumanResource/User/Security/RolesGuard'; |
||
| 18 | |||
| 19 | @Controller('customers') |
||
| 20 | @ApiTags('Customer') |
||
| 21 | @ApiBearerAuth() |
||
| 22 | @UseGuards(AuthGuard('bearer'), RolesGuard) |
||
| 23 | export class GetCustomerAction { |
||
| 24 | constructor( |
||
| 25 | @Inject('IQueryBus') |
||
| 26 | private readonly queryBus: IQueryBus |
||
| 27 | ) {} |
||
| 28 | |||
| 29 | @Get(':id') |
||
| 30 | @Roles(UserRole.COOPERATOR, UserRole.EMPLOYEE) |
||
| 31 | @ApiOperation({summary: 'Get customer'}) |
||
| 32 | public async index(@Param() dto: IdDTO): Promise<CustomerView> { |
||
| 33 | try { |
||
| 34 | return await this.queryBus.execute(new GetCustomerByIdQuery(dto.id)); |
||
| 35 | } catch (e) { |
||
| 36 | throw new NotFoundException(e.message); |
||
| 37 | } |
||
| 38 | } |
||
| 39 | } |
||
| 40 |