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