Conditions | 3 |
Total Lines | 55 |
Code Lines | 37 |
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 } from '@nestjs/common'; |
||
25 | |||
26 | public async execute(command: CreateLeaveRequestCommand): Promise<string> { |
||
27 | const { |
||
28 | user, |
||
29 | endDate, |
||
30 | endsAllDay, |
||
31 | type, |
||
32 | startDate, |
||
33 | startsAllDay, |
||
34 | comment |
||
35 | } = command; |
||
36 | |||
37 | if ( |
||
38 | true === |
||
39 | (await this.doesLeaveRequestExistForPeriod.isSatisfiedBy( |
||
40 | user, |
||
41 | startDate, |
||
42 | endDate |
||
43 | )) |
||
44 | ) { |
||
45 | throw new LeaveRequestAlreadyExistForThisPeriodException(); |
||
46 | } |
||
47 | |||
48 | if ( |
||
49 | true === |
||
50 | (await this.doesLeaveExistForPeriod.isSatisfiedBy( |
||
51 | user, |
||
52 | startDate, |
||
53 | endDate |
||
54 | )) |
||
55 | ) { |
||
56 | throw new EventsOrLeavesAlreadyExistForThisPeriodException(); |
||
57 | } |
||
58 | |||
59 | const leaveRequest = await this.leaveRequestRepository.save( |
||
60 | new LeaveRequest( |
||
61 | user, |
||
62 | type, |
||
63 | startDate, |
||
64 | startsAllDay, |
||
65 | endDate, |
||
66 | endsAllDay, |
||
67 | comment |
||
68 | ) |
||
69 | ); |
||
70 | |||
71 | this.commandBus.execute( |
||
72 | new CreateNotificationCommand( |
||
73 | NotificationType.POST, |
||
74 | 'Demande de congés', |
||
75 | leaveRequest |
||
76 | ) |
||
77 | ); |
||
78 | |||
79 | return leaveRequest.getId(); |
||
80 | } |
||
82 |