feat(resource): ad-hoc blocking, 409 recovery, and the rest of the flake

Ad-hoc resource blocking
- "The laser is being serviced this afternoon" is a specific range, not a change
  to the resource's working pattern. It stays separate from calendar exceptions
  and the modal says which is which — merging them means either an afternoon's
  closure lives in the calendar forever, or a change to working hours vanishes
  with one click
- Blocking a range that already holds an appointment is refused with 409 rather
  than silently taking capacity back; the appointment is still there and someone
  has to decide about it first
- Deleting an occupancy that belongs to an appointment is refused too, otherwise
  a patient's booking would quietly lose its resource with no record

409 on hold now recovers
Saying "someone just took it" is not enough — the operator would have to search
again by hand. The page drops the stale selection and refetches, so alternatives
are on screen immediately.

Flake, second half
The earlier fix only covered createUser's retry path. Any test that trips a
unique constraint closes the EntityManager, and the next test inherits the same
closed instance from the container. setUp now resets the registry when it finds
a closed manager, so a test's starting state no longer depends on how the
previous one failed.

Three consecutive full runs green: 1340 tests.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hamed
2026-07-31 20:50:43 +03:30
co-authored by Claude Opus 5
parent 3dcc7c2ec0
commit 0127b463a6
10 changed files with 639 additions and 11 deletions
+43
View File
@@ -364,3 +364,46 @@ ddev exec php bin/phpunit tests/Resource # ۵۲ تست / ۱۲۹ assertion
ddev exec php vendor/bin/phpstan analyse src/Resource
npx vitest run assets/admin/pages/ResourcesPage.test.tsx
```
---
## مسدودسازی موردی
«این بعدازظهر دستگاه سرویس دارد» — یک بازهٔ مشخص که منبع در دسترس نیست.
| | مسدودسازی موردی | استثنای تقویم |
|---|---|---|
| چیست | یک بازهٔ مشخص | تغییر الگوی تکرارشوندهٔ کاری |
| کجا | `resource_occupancy` | `resource_exceptions` |
| چقدر می‌ماند | تا وقتی حذفش کنی | بخشی از تعریف تقویم |
ادغامشان یعنی یا تعطیلی یک بعدازظهر برای همیشه در تقویم بماند، یا تغییر ساعت کاری با
یک کلیک ناپدید شود.
### GET `/api/v1/resource/{uuid}/blocks`
| Query | Type | Description |
|---|---|---|
| `from` / `to` | int | پیش‌فرض: از حالا تا ۳۰ روز بعد |
فقط مسدودسازی‌های **دستی** برمی‌گردند؛ اشغالِ نوبت‌ها اینجا نمی‌آید.
### POST `/api/v1/resource/{uuid}/blocks`
```json
{ "starts_at": 1785600000, "ends_at": 1785614400, "reason": "سرویس دوره‌ای دستگاه" }
```
| Code | HTTP | Description |
|---|---|---|
| `ERR_VALIDATION_002` | 422 | بازه غایب |
| `ERR_VALIDATION_001` | 422 | پایان قبل از شروع |
| `ERR_SLOT_TAKEN` | 409 | در این بازه نوبت یا رزرو موقت هست |
مسدودسازی روی بازه‌ای که نوبت دارد **ظرفیت را پس نمی‌گیرد**: نوبت سرجایش می‌ماند و
کاربر باید اول تکلیفش را روشن کند.
### DELETE `/api/v1/resource-block/{uuid}`
اشغالی که به نوبت یا رزرو موقت وصل است از این مسیر حذف **نمی‌شود** (`422`) — وگرنه
نوبت بیمار بی‌صدا منبعش را از دست می‌داد.