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