wip
This commit is contained in:
@@ -7,22 +7,31 @@ 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\Domain\Slack\SignatureHandler;
|
||||
use Toby\Domain\Slack\Traits\FindsUserBySlackId;
|
||||
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)";
|
||||
use FindsUserBySlackId;
|
||||
|
||||
protected $signature = "toby zdalnie";
|
||||
protected $description = "Pracuj dzisiaj zdalnie";
|
||||
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$date = $this->getDateFromArgument($this->getArgument('kiedy') ?? "dzisiaj");
|
||||
$user = $this->findUserBySlackId($request->userId);
|
||||
|
||||
$this->createRemoteday($user, Carbon::today());
|
||||
|
||||
return $this->respondToSlack(":white_check_mark: Pracujesz dzisiaj zdalnie");
|
||||
}
|
||||
|
||||
protected function createRemoteday(User $user, Carbon $date): void
|
||||
{
|
||||
$yearPeriod = YearPeriod::findByYear($date->year);
|
||||
|
||||
app(CreateAction::class)->execute([
|
||||
@@ -33,27 +42,5 @@ class HomeOffice extends SignatureHandler
|
||||
"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