Refactor Catalog API: Remove Create Catalog Item Endpoint and Update Related Logic

- Removed the "Create Catalog" endpoint from the Postman collection.
- Updated the CatalogController to handle tenant-specific catalog items based on active events.
- Refactored CatalogItem model to automatically set event_id based on tenant's active_event_id during creation.
- Deleted StoreCatalogItemRequest and CatalogItemResource as they are no longer needed.
- Updated various services and controllers to utilize the new tenant-based catalog item retrieval logic.
- Added tests to ensure that catalog reads are limited to items associated with the active event.
This commit is contained in:
2026-09-18 13:51:13 -03:00
parent cdc17a13e2
commit 22ef5619f3
21 changed files with 107 additions and 482 deletions

View File

@@ -278,7 +278,7 @@ class EntryService
private function entryQuery(Tenant $tenant): Builder
{
return CatalogItem::query()
->where('tenant_code', $tenant->codigo)
->forTenantCatalog($tenant)
->where('slug', 'entrada');
}

View File

@@ -25,7 +25,7 @@ class AccommodationService
public function current(Tenant $tenant): ?CatalogItem
{
return CatalogItem::query()
->where('tenant_code', $tenant->codigo)
->forTenantCatalog($tenant)
->where('slug', 'alojamiento')
->with([
'itemAttributes.attribute.options',
@@ -126,7 +126,7 @@ class AccommodationService
'nombre' => 'Alojamientos',
]);
$accommodation = CatalogItem::withTrashed()
->where('tenant_code', $tenant->codigo)
->forTenantCatalog($tenant)
->where('slug', 'alojamiento')
->lockForUpdate()
->first();

View File

@@ -22,7 +22,7 @@ class EntryService
public function all(Tenant $tenant): Collection
{
return CatalogItem::query()
->where('tenant_code', $tenant->codigo)
->forTenantCatalog($tenant)
->whereHas('category', fn ($query) => $query->where('nombre', 'Entradas'))
->whereHas('variants', fn ($query) => $query
->whereNull('replaced_by_variant_id')
@@ -84,7 +84,7 @@ class EntryService
{
$entry = CatalogItem::query()
->whereKey($entryId)
->where('tenant_code', $tenant->codigo)
->forTenantCatalog($tenant)
->whereHas('category', fn ($query) => $query->where('nombre', 'Entradas'))
->firstOrFail();
@@ -96,7 +96,7 @@ class EntryService
{
$catalogItem = CatalogItem::query()
->whereKey($entry['id'])
->where('tenant_code', $tenant->codigo)
->forTenantCatalog($tenant)
->whereHas('category', fn ($query) => $query->where('nombre', 'Entradas'))
->lockForUpdate()
->firstOrFail();

View File

@@ -33,7 +33,7 @@ class FoodService
public function current(Tenant $tenant): ?CatalogItem
{
return CatalogItem::query()
->where('tenant_code', $tenant->codigo)
->forTenantCatalog($tenant)
->where('slug', 'comida')
->with([
'variants.catalogItem',
@@ -119,7 +119,7 @@ class FoodService
{
return DB::transaction(function () use ($tenant, $variants): CatalogItem {
$food = CatalogItem::query()
->where('tenant_code', $tenant->codigo)
->forTenantCatalog($tenant)
->where('slug', 'comida')
->lockForUpdate()
->firstOrFail();
@@ -233,7 +233,7 @@ class FoodService
'nombre' => 'Comidas',
]);
$food = CatalogItem::withTrashed()
->where('tenant_code', $tenant->codigo)
->forTenantCatalog($tenant)
->where('slug', 'comida')
->lockForUpdate()
->first();

View File

@@ -27,7 +27,7 @@ class MerchandiseService
public function all(Tenant $tenant): Collection
{
return CatalogItem::query()
->where('tenant_code', $tenant->codigo)
->forTenantCatalog($tenant)
->whereHas('category', fn ($query) => $query->where('nombre', 'Merchandising'))
->with([
'itemAttributes.attribute.options',
@@ -164,7 +164,7 @@ class MerchandiseService
): CatalogItem {
$item = CatalogItem::query()
->whereKey($itemId)
->where('tenant_code', $tenant->codigo)
->forTenantCatalog($tenant)
->where('category_id', $category->id)
->lockForUpdate()
->first();