|
1
|
|
|
import { Inject, Injectable } from '@nestjs/common'; |
|
2
|
|
|
import { IQueryBus } from '@nestjs/cqrs'; |
|
3
|
|
|
import { GetUsersQuery } from 'src/Application/HumanResource/User/Query/GetUsersQuery'; |
|
4
|
|
|
import { UserView } from 'src/Application/HumanResource/User/View/UserView'; |
|
5
|
|
|
import { ILeaveRequestsOverview } from 'src/Domain/HumanResource/Leave/ILeaveRequestsOverview'; |
|
6
|
|
|
import { Table } from 'src/Infrastructure/Tables'; |
|
7
|
|
|
import { HtmlColumn } from 'src/Infrastructure/Tables/HtmlColumn'; |
|
8
|
|
|
import { RowFactory } from 'src/Infrastructure/Tables/RowFactory'; |
|
9
|
|
|
import { ITemplates } from 'src/Infrastructure/Templates/ITemplates'; |
|
10
|
|
|
|
|
11
|
|
|
@Injectable() |
|
12
|
|
|
export class LeaveRequestsOverviewTableFactory { |
|
13
|
|
|
constructor( |
|
14
|
|
|
@Inject('IQueryBus') |
|
15
|
|
|
private queryBus: IQueryBus, |
|
16
|
|
|
private rowFactory: RowFactory, |
|
17
|
|
|
@Inject('ITemplates') |
|
18
|
|
|
private templates: ITemplates |
|
19
|
|
|
) {} |
|
20
|
|
|
|
|
21
|
|
|
public async create( |
|
22
|
|
|
overview: ILeaveRequestsOverview, |
|
23
|
|
|
userId: string |
|
24
|
|
|
): Promise<Table> { |
|
25
|
|
|
const users: UserView[] = await this.queryBus.execute( |
|
26
|
|
|
new GetUsersQuery(false, true) |
|
27
|
|
|
); |
|
28
|
|
|
|
|
29
|
|
|
const columns = [ |
|
30
|
|
|
'leaves-user', |
|
31
|
|
|
new HtmlColumn( |
|
32
|
|
|
'leaves-overview-daysRemaining', |
|
33
|
|
|
this.templates.render( |
|
34
|
|
|
'pages/leave_requests/overview/days_remaining_column_header.njk', |
|
35
|
|
|
{ |
|
36
|
|
|
daysPerYear: overview.daysPerYear |
|
37
|
|
|
} |
|
38
|
|
|
) |
|
39
|
|
|
) |
|
40
|
|
|
]; |
|
41
|
|
|
|
|
42
|
|
|
const row = this.rowFactory |
|
43
|
|
|
.createBuilder() |
|
44
|
|
|
.template('pages/leave_requests/overview/user_cell.njk', { |
|
45
|
|
|
users, |
|
46
|
|
|
userId |
|
47
|
|
|
}) |
|
48
|
|
|
.template('pages/leave_requests/overview/days_remaining_cell.njk', { |
|
49
|
|
|
daysRemaining: overview.daysRemaining |
|
50
|
|
|
}) |
|
51
|
|
|
.build(); |
|
52
|
|
|
|
|
53
|
|
|
return new Table(columns, [row]); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|