This commit is contained in:
Adrian Hopek
2022-03-01 12:25:07 +01:00
parent 92784846dc
commit a37be18da6
10 changed files with 85 additions and 62 deletions

View File

@@ -3,30 +3,10 @@
declare(strict_types=1);
use Illuminate\Support\Facades\Route;
use Toby\Domain\UserVacationStatsRetriever;
use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\YearPeriod;
use Toby\Infrastructure\Http\Controllers\Api\CalculateUserVacationStatsController;
use Toby\Infrastructure\Http\Controllers\Api\CalculateVacationDaysController;
use Toby\Infrastructure\Http\Requests\Api\CalculateVacationStatsRequest;
Route::middleware("auth:sanctum")->group(function (): void {
Route::post("calculate-vacation-days", CalculateVacationDaysController::class);
Route::post("calculate-vacations-stats", function (CalculateVacationStatsRequest $request, UserVacationStatsRetriever $vacationStatsRetriever) {
/** @var User $user */
$user = User::query()->find($request->get("user"));
$yearPeriod = YearPeriod::current();
$limit = $vacationStatsRetriever->getVacationDaysLimit($user, $yearPeriod);
$used = $vacationStatsRetriever->getUsedVacationDays($user, $yearPeriod);
$pending = $vacationStatsRetriever->getPendingVacationDays($user, $yearPeriod);
$other = $vacationStatsRetriever->getOtherApprovedVacationDays($user, $yearPeriod);
return [
"limit" => $limit,
"remaining" => $limit - $used - $pending,
"used" => $used,
"pending" => $pending,
"other" => $other,
];
});
Route::post("calculate-vacations-stats", CalculateUserVacationStatsController::class);
});