feat(services): pick a global category from the service page
The service page could not say which category a service belongs to, so the
containment edges defined in settings had nothing to match against.
A Categories tab now selects one — and only selects. Creating, renaming and
deleting stay in Settings > Categories: if every page could create one,
"whole body" would exist three times with three spellings and the
includes edge would stop catching anything.
PATCH /api/v1/service-item/{uuid} carries the choice as
catalog_category_uuid. Absent field leaves the current category alone, null
clears it, and a category from another environment is refused with 422 —
the uuid arrives in the request body where TenantFilter does not reach.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ use App\ClinicService\Entity\Tariff;
|
||||
use App\Clinic\Security\ClinicDoctorAccessChecker;
|
||||
use App\Secretary\Security\SecretaryAccessChecker;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\ClinicService\Repository\CatalogCategoryRepository;
|
||||
use App\ClinicService\Repository\ServiceItemAuditLogRepository;
|
||||
use App\ClinicService\Repository\ServiceItemRepository;
|
||||
use App\ClinicService\Repository\ServiceSectionRepository;
|
||||
@@ -55,6 +56,7 @@ class ClinicServiceController extends BaseController
|
||||
private readonly RequestStack $requestStack,
|
||||
private readonly SecretaryAccessChecker $secretaryAccess,
|
||||
private readonly ClinicDoctorAccessChecker $clinicDoctorAccess,
|
||||
private readonly CatalogCategoryRepository $catalogCategoryRepo,
|
||||
) {}
|
||||
|
||||
/** گِیتِ ترکیبی: منشی + پزشکِ عضوِ کلینیک (هرکدام فقط نقشِ خودش را محدود میکند). */
|
||||
@@ -120,6 +122,36 @@ class ClinicServiceController extends BaseController
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* دستهٔ کاتالوگ سرویس — از دستهٔ **سراسری** محیط انتخاب میشود.
|
||||
*
|
||||
* uuid از بدنهٔ درخواست میآید و `TenantFilter` رویش اعمال نمیشود، پس محیط دسته صریحاً
|
||||
* با محیط کاربر مقایسه میشود. `null` یعنی «بدون دسته»، پس با `array_key_exists`
|
||||
* تشخیص داده میشود نه `isset`.
|
||||
*/
|
||||
private function applyCatalogCategory(ServiceItem $item, array $data, string $entityType, ?int $entityId): ?JsonResponse
|
||||
{
|
||||
if (!array_key_exists('catalog_category_uuid', $data)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$uuid = $data['catalog_category_uuid'];
|
||||
if ($uuid === null || $uuid === '') {
|
||||
$item->setCatalogCategory(null);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$category = $this->catalogCategoryRepo->findByUuid((string) $uuid);
|
||||
if ($category === null || $category->getEntityType() !== $entityType || $category->getEntityId() !== $entityId) {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'دستهبندی یافت نشد', 422, 'catalog_category_uuid');
|
||||
}
|
||||
|
||||
$item->setCatalogCategory($category);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** نوع خدمت (سرپایی/بستری) را ست میکند؛ مقدار نامعتبر ۴۲۲ میدهد. */
|
||||
private function applyServiceCategory(ServiceItem $item, array $data): ?JsonResponse
|
||||
{
|
||||
@@ -380,6 +412,9 @@ class ClinicServiceController extends BaseController
|
||||
if (($categoryError = $this->applyServiceCategory($item, $data)) !== null) {
|
||||
return $categoryError;
|
||||
}
|
||||
if (($catalogError = $this->applyCatalogCategory($item, $data, $entityType, $entityId)) !== null) {
|
||||
return $catalogError;
|
||||
}
|
||||
$packageError = $this->applyInventoryPackage($item, $data, $entityType, $entityId);
|
||||
if ($packageError !== null) {
|
||||
return $packageError;
|
||||
@@ -435,6 +470,9 @@ class ClinicServiceController extends BaseController
|
||||
if (($categoryError = $this->applyServiceCategory($item, $data)) !== null) {
|
||||
return $categoryError;
|
||||
}
|
||||
if (($catalogError = $this->applyCatalogCategory($item, $data, $entityType, $entityId)) !== null) {
|
||||
return $catalogError;
|
||||
}
|
||||
$packageError = $this->applyInventoryPackage($item, $data, $entityType, $entityId);
|
||||
if ($packageError !== null) {
|
||||
return $packageError;
|
||||
|
||||
Reference in New Issue
Block a user