Conditions | 3 |
Total Lines | 56 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import { Inject, Injectable } from '@nestjs/common'; |
||
25 | |||
26 | public create(leaveRequests: LeaveRequestView[], userId: string): Table { |
||
27 | const columns = [ |
||
28 | 'leaves-user', |
||
29 | 'leaves-period', |
||
30 | 'leaves-duration', |
||
31 | 'leaves-type', |
||
32 | 'leaves-status', |
||
33 | 'common-actions' |
||
34 | ]; |
||
35 | |||
36 | const rows = leaveRequests.map( |
||
37 | (leaveRequest): Row => { |
||
38 | const actions: ActionsOptions = { |
||
39 | view: { |
||
40 | url: this.resolver.resolve('people_leave_requests_detail', { |
||
41 | id: leaveRequest.id |
||
42 | }) |
||
43 | } |
||
44 | }; |
||
45 | |||
46 | if ( |
||
47 | leaveRequest.user.id === userId && |
||
48 | leaveRequest.status === Status.PENDING |
||
49 | ) { |
||
50 | actions.edit = { |
||
51 | url: this.resolver.resolve('people_leave_requests_edit', { |
||
52 | id: leaveRequest.id |
||
53 | }) |
||
54 | }; |
||
55 | } |
||
56 | |||
57 | if (leaveRequest.canCancel) { |
||
58 | actions.delete = { |
||
59 | url: this.resolver.resolve('people_leave_requests_delete', { |
||
60 | id: leaveRequest.id |
||
61 | }) |
||
62 | }; |
||
63 | } |
||
64 | |||
65 | return this.rowFactory |
||
66 | .createBuilder() |
||
67 | .value(formatFullName(leaveRequest.user)) |
||
68 | .trans('leaves-period-value', { |
||
69 | startDate: leaveRequest.startDate, |
||
70 | endDate: leaveRequest.endDate |
||
71 | }) |
||
72 | .trans('leaves-duration-value', { days: leaveRequest.duration }) |
||
73 | .trans('leaves-type-value', { type: leaveRequest.type }) |
||
74 | .apply(builder => this.addStatusRow(builder, leaveRequest.status)) |
||
75 | .actions(actions) |
||
76 | .build(); |
||
77 | } |
||
78 | ); |
||
79 | |||
80 | return new Table(columns, rows); |
||
81 | } |
||
128 |