| Conditions | 4 |
| Total Lines | 58 |
| Code Lines | 41 |
| 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'; |
||
| 21 | |||
| 22 | public async execute(command: CreateLeaveRequestCommand): Promise<string> { |
||
| 23 | const { |
||
| 24 | user, |
||
| 25 | endDate, |
||
| 26 | endsAllDay, |
||
| 27 | type, |
||
| 28 | startDate, |
||
| 29 | startsAllDay |
||
| 30 | } = command; |
||
| 31 | |||
| 32 | let { comment } = command; |
||
| 33 | |||
| 34 | if ( |
||
| 35 | true === |
||
| 36 | (await this.doesLeaveRequestExistForPeriod.isSatisfiedBy( |
||
| 37 | user, |
||
| 38 | startDate, |
||
| 39 | endDate |
||
| 40 | )) |
||
| 41 | ) { |
||
| 42 | throw new LeaveRequestAlreadyExistForThisPeriodException(); |
||
| 43 | } |
||
| 44 | |||
| 45 | if ( |
||
| 46 | true === |
||
| 47 | (await this.doesLeaveExistForPeriod.isSatisfiedBy( |
||
| 48 | user, |
||
| 49 | startDate, |
||
| 50 | endDate |
||
| 51 | )) |
||
| 52 | ) { |
||
| 53 | throw new EventsOrLeavesAlreadyExistForThisPeriodException(); |
||
| 54 | } |
||
| 55 | |||
| 56 | if ( |
||
| 57 | true === |
||
| 58 | this.DoesLeaveRequestLackPostponedWorkedFreeDays.isSatisfiedBy( |
||
| 59 | startDate, |
||
| 60 | endDate |
||
| 61 | ) |
||
| 62 | ) { |
||
| 63 | comment += ` ⚠️ Cette demande de congé contient un ou plusieurs jour(s) férié(s) glissant non pris en compte.`; |
||
| 64 | } |
||
| 65 | |||
| 66 | const leaveRequest = await this.leaveRequestRepository.save( |
||
| 67 | new LeaveRequest( |
||
| 68 | user, |
||
| 69 | type, |
||
| 70 | startDate, |
||
| 71 | startsAllDay, |
||
| 72 | endDate, |
||
| 73 | endsAllDay, |
||
| 74 | comment |
||
| 75 | ) |
||
| 76 | ); |
||
| 77 | |||
| 78 | return leaveRequest.getId(); |
||
| 79 | } |
||
| 81 |