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