wip
This commit is contained in:
		
							
								
								
									
										59
									
								
								app/Domain/Slack/Handlers/HomeOffice.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								app/Domain/Slack/Handlers/HomeOffice.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,59 @@ | ||||
| <?php | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Toby\Domain\Slack\Handlers; | ||||
|  | ||||
| use Illuminate\Support\Carbon; | ||||
| use Spatie\SlashCommand\Request; | ||||
| use Spatie\SlashCommand\Response; | ||||
| use Spatie\SlashCommand\Handlers\SignatureHandler; | ||||
| use Toby\Domain\Actions\VacationRequest\CreateAction; | ||||
| use Toby\Domain\Enums\VacationType; | ||||
| use Toby\Eloquent\Models\User; | ||||
| use Toby\Eloquent\Models\YearPeriod; | ||||
|  | ||||
| class HomeOffice extends SignatureHandler | ||||
| { | ||||
|     protected $signature = "toby zdalnie {kiedy?}"; | ||||
|     protected $description = "Pracuj zdalnie wybranego dnia (domyślnie dzisiaj)"; | ||||
|  | ||||
|     public function handle(Request $request): Response | ||||
|     { | ||||
|         $date = $this->getDateFromArgument($this->getArgument('kiedy') ?? "dzisiaj"); | ||||
|         $user = $this->findUserBySlackId($request->userId); | ||||
|  | ||||
|         $yearPeriod = YearPeriod::findByYear($date->year); | ||||
|  | ||||
|         app(CreateAction::class)->execute([ | ||||
|             "user_id" => $user->id, | ||||
|             "type" => VacationType::HomeOffice, | ||||
|             "from" => $date, | ||||
|             "to" => $date, | ||||
|             "year_period_id" => $yearPeriod->id, | ||||
|             "flow_skipped" => false, | ||||
|         ], $user); | ||||
|  | ||||
|         return $this->respondToSlack("Praca zdalna dnia {$date->toDisplayString()} została utworzona pomyślnie.") | ||||
|             ->displayResponseToEveryoneOnChannel(); | ||||
|     } | ||||
|  | ||||
|     protected function getDateFromArgument(string $argument): Carbon | ||||
|     { | ||||
|         return match ($argument) { | ||||
|             "dzisiaj" => Carbon::today(), | ||||
|             "jutro" => Carbon::tomorrow(), | ||||
|             default => Carbon::create($argument), | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     protected function findUserBySlackId(string $slackId): User | ||||
|     { | ||||
|         /** @var User $user */ | ||||
|         $user = User::query() | ||||
|             ->whereRelation("profile", "slack_id", $slackId) | ||||
|             ->first(); | ||||
|  | ||||
|         return $user; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user