| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 41 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { |
||
| 2 | Get, |
||
| 3 | Controller, |
||
| 4 | Inject, |
||
| 5 | BadRequestException, |
||
| 6 | UseGuards |
||
| 7 | } from '@nestjs/common'; |
||
| 8 | import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger'; |
||
| 9 | import { AuthGuard } from '@nestjs/passport'; |
||
| 10 | import { User, UserRole } from 'src/Domain/HumanResource/User/User.entity'; |
||
| 11 | import { RolesGuard } from 'src/Infrastructure/HumanResource/User/Security/RolesGuard'; |
||
| 12 | import { Roles } from 'src/Infrastructure/HumanResource/User/Decorator/Roles'; |
||
| 13 | import { LoggedUser } from '../../User/Decorator/LoggedUser'; |
||
| 14 | import { IQueryBus } from '@nestjs/cqrs'; |
||
| 15 | import { CountMealTicketPerMonthQuery } from 'src/Application/HumanResource/MealTicket/Query/CountMealTicketPerMonthQuery'; |
||
| 16 | |||
| 17 | @Controller('meal-tickets') |
||
| 18 | @ApiTags('Human Resource') |
||
| 19 | @ApiBearerAuth() |
||
| 20 | @UseGuards(AuthGuard('bearer'), RolesGuard) |
||
| 21 | export class GetAvailableMealTicketsAction { |
||
| 22 | constructor( |
||
| 23 | @Inject('IQueryBus') |
||
| 24 | private readonly queryBus: IQueryBus |
||
| 25 | ) {} |
||
| 26 | |||
| 27 | @Get('count') |
||
| 28 | @Roles(UserRole.COOPERATOR, UserRole.EMPLOYEE) |
||
| 29 | @ApiOperation({ summary: 'Get all available Meal Tickets' }) |
||
| 30 | public async index(@LoggedUser() user: User) { |
||
| 31 | try { |
||
| 32 | const result = await this.queryBus.execute( |
||
| 33 | new CountMealTicketPerMonthQuery(user, new Date()) |
||
| 34 | ); |
||
| 35 | return result; |
||
| 36 | } catch (e) { |
||
| 37 | throw new BadRequestException(e.message); |
||
| 38 | } |
||
| 39 | } |
||
| 40 | } |
||
| 41 |