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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user