fix(capacity): stabilize PTO flows and calendar consistency

Make PTO creation immediately approved, add PTO deletion, and ensure cache invalidation updates individual/team/revenue capacity consistently.

Harden holiday duplicate handling (422), support PTO-day availability overrides without disabling edits, and align tests plus OpenSpec artifacts with the new behavior.
This commit is contained in:
2026-02-19 22:47:39 -05:00
parent 0a9fdd248b
commit b821713cc7
21 changed files with 1081 additions and 128 deletions

View File

@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
use App\Http\Resources\HolidayResource;
use App\Models\Holiday;
use App\Services\CapacityService;
use Illuminate\Database\UniqueConstraintViolationException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -65,6 +66,7 @@ class HolidayController extends Controller
* "description": "Office closed"
* }
* }
* @response 422 {"message":"A holiday already exists for this date.","errors":{"date":["A holiday already exists for this date."]}}
*/
public function store(Request $request): JsonResponse
{
@@ -74,10 +76,19 @@ class HolidayController extends Controller
'description' => 'nullable|string',
]);
$holiday = Holiday::create($data);
$this->capacityService->forgetCapacityCacheForMonth($holiday->date->format('Y-m'));
try {
$holiday = Holiday::create($data);
$this->capacityService->forgetCapacityCacheForMonth($holiday->date->format('Y-m'));
return $this->wrapResource(new HolidayResource($holiday), 201);
return $this->wrapResource(new HolidayResource($holiday), 201);
} catch (UniqueConstraintViolationException $e) {
return response()->json([
'message' => 'A holiday already exists for this date.',
'errors' => [
'date' => ['A holiday already exists for this date.'],
],
], 422);
}
}
/**