1
|
|
|
import { Controller, Inject, UseGuards, Get, Query } 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 { RolesGuard } from 'src/Infrastructure/HumanResource/User/Security/RolesGuard'; |
6
|
|
|
import { UserRole } from 'src/Domain/HumanResource/User/User.entity'; |
7
|
|
|
import { Roles } from 'src/Infrastructure/HumanResource/User/Decorator/Roles'; |
8
|
|
|
import { LeaveRequestView } from 'src/Application/HumanResource/Leave/View/LeaveRequestView'; |
9
|
|
|
import { GetLeaveRequestsQuery } from 'src/Application/HumanResource/Leave/Query/GetLeaveRequestsQuery'; |
10
|
|
|
import { PaginationDTO } from 'src/Infrastructure/Common/DTO/PaginationDTO'; |
11
|
|
|
import { Pagination } from 'src/Application/Common/Pagination'; |
12
|
|
|
import { Status } from 'src/Domain/HumanResource/Leave/LeaveRequest.entity'; |
13
|
|
|
|
14
|
|
|
@Controller('leaves') |
15
|
|
|
@ApiTags('Human Resource') |
16
|
|
|
@ApiBearerAuth() |
17
|
|
|
@UseGuards(AuthGuard('bearer'), RolesGuard) |
18
|
|
|
export class GetLeavesAction { |
19
|
|
|
constructor( |
20
|
|
|
@Inject('IQueryBus') |
21
|
|
|
private readonly queryBus: IQueryBus |
22
|
|
|
) {} |
23
|
|
|
|
24
|
|
|
@Get() |
25
|
|
|
@Roles(UserRole.COOPERATOR, UserRole.EMPLOYEE) |
26
|
|
|
@ApiOperation({summary: 'Get all leaves'}) |
27
|
|
|
public async index( |
28
|
|
|
@Query() pagination: PaginationDTO |
29
|
|
|
): Promise<Pagination<LeaveRequestView>> { |
30
|
|
|
return await this.queryBus.execute( |
31
|
|
|
new GetLeaveRequestsQuery(pagination.page, Status.ACCEPTED) |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|