feat(food): implement FoodFormController and FoodFormService; add FoodFormResource for managing food options and routes
This commit is contained in:
@@ -12,6 +12,14 @@ class AccommodationResource extends JsonResource
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
if ($this->resource === null) {
|
||||
return [
|
||||
'id' => null,
|
||||
'name' => 'Alojamiento',
|
||||
'variants' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$typeAttribute = $this->itemAttributes
|
||||
->first(fn ($itemAttribute) => $itemAttribute->attribute?->codigo === 'tipo_alojamiento');
|
||||
$options = $typeAttribute?->attribute?->options?->keyBy('value') ?? collect();
|
||||
|
||||
@@ -12,6 +12,14 @@ class FoodResource extends JsonResource
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
if ($this->resource === null) {
|
||||
return [
|
||||
'id' => null,
|
||||
'name' => 'Comida',
|
||||
'variants' => [],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->nombre,
|
||||
|
||||
@@ -20,7 +20,7 @@ class AccommodationService
|
||||
{
|
||||
private const ATTRIBUTE_CODE = 'tipo_alojamiento';
|
||||
|
||||
public function current(Tenant $tenant): CatalogItem
|
||||
public function current(Tenant $tenant): ?CatalogItem
|
||||
{
|
||||
return CatalogItem::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
@@ -31,7 +31,7 @@ class AccommodationService
|
||||
'variants.inventory',
|
||||
'variants.definitions',
|
||||
])
|
||||
->firstOrFail();
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,7 +20,7 @@ class FoodService
|
||||
{
|
||||
private const ATTRIBUTE_CODES = ['event_date', 'horario', 'servicio'];
|
||||
|
||||
public function current(Tenant $tenant): CatalogItem
|
||||
public function current(Tenant $tenant): ?CatalogItem
|
||||
{
|
||||
return CatalogItem::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
@@ -32,7 +32,7 @@ class FoodService
|
||||
'variants.eventDates',
|
||||
'variants.definitions.itemAttribute.attribute',
|
||||
])
|
||||
->firstOrFail();
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -282,7 +282,7 @@ class FoodService
|
||||
/** @param Collection<string, ItemAttribute> $itemAttributes */
|
||||
private function syncDefinitions(Variant $variant, Collection $itemAttributes, array $data): void
|
||||
{
|
||||
$definitionAttributes = $itemAttributes->only(['horario', 'servicio']);
|
||||
$definitionAttributes = $itemAttributes->toBase()->only(['horario', 'servicio']);
|
||||
$variant->definitions()->whereIn('item_attribute_id', $definitionAttributes->pluck('id'))->delete();
|
||||
$variant->definitions()->createMany([
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user