-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathListLeaveRequestsController.ts
More file actions
65 lines (58 loc) · 2.28 KB
/
Copy pathListLeaveRequestsController.ts
File metadata and controls
65 lines (58 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {
Controller,
Inject,
UseGuards,
Get,
Render,
Query
} from '@nestjs/common';
import { IQueryBus } from 'src/Application/IQueryBus';
import { User } from 'src/Domain/HumanResource/User/User.entity';
import { GetLeaveRequestsQuery } from 'src/Application/HumanResource/Leave/Query/GetLeaveRequestsQuery';
import { IsAuthenticatedGuard } from 'src/Infrastructure/HumanResource/User/Security/IsAuthenticatedGuard';
import { WithName } from 'src/Infrastructure/Common/ExtendedRouting/WithName';
import { Pagination } from 'src/Application/Common/Pagination';
import { LeaveRequestView } from 'src/Application/HumanResource/Leave/View/LeaveRequestView';
import { LoggedUser } from '../../User/Decorator/LoggedUser';
import { LeaveRequestTableFactory } from '../Table/LeaveRequestTableFactory';
import { LeaveRequestsOverviewTableFactory } from '../Table/LeaveRequestOverviewTableFactory';
import { GetLeaveRequestsOverviewQuery } from 'src/Application/HumanResource/Leave/Query/GetLeaveRequestsOverviewQuery';
import { ListLeaveRequestsControllerDTO } from '../DTO/ListLeaveRequestsControllerDTO';
@Controller('app/people/leave_requests')
@UseGuards(IsAuthenticatedGuard)
export class ListLeaveRequestsController {
constructor(
@Inject('IQueryBus')
private readonly queryBus: IQueryBus,
private readonly tableFactory: LeaveRequestTableFactory,
private readonly overviewTableFactory: LeaveRequestsOverviewTableFactory
) {}
@Get()
@WithName('people_leave_requests_list')
@Render('pages/leave_requests/list.njk')
public async get(
@Query() dto: ListLeaveRequestsControllerDTO,
@LoggedUser() user: User
) {
const pagination: Pagination<LeaveRequestView> = await this.queryBus.execute(
new GetLeaveRequestsQuery(user.getId(), dto.page)
);
const table = this.tableFactory.create(pagination.items, user.getId());
const userId = dto.userId ? dto.userId : user['id'];
const overview = await this.queryBus.execute(
new GetLeaveRequestsOverviewQuery(new Date(), userId)
);
const overviewTable = await this.overviewTableFactory.create(
overview,
userId
);
const calendarToken = process.env.CALENDAR_TOKEN;
return {
table,
overviewTable,
pagination,
currentPage: dto.page,
calendarToken
};
}
}