refactor(catalog): nest catalog routes under tenant

Move Catalog endpoints under /api/tenants/{tenant:codigo} and derive tenant
context from the route instead of request payload fields.

- scope marcas, categorias, productos, and product-attributes by tenant
- enforce tenant ownership in catalog controllers
- remove tenant_codigo and tenant_code from Catalog request validation
- update product attribute tests to use tenant-scoped routes
This commit is contained in:
2026-06-24 15:16:38 -03:00
parent c6e5177df1
commit 1907178e52
13 changed files with 123 additions and 50 deletions

View File

@@ -17,7 +17,6 @@ class StoreBrandRequest extends FormRequest
public function rules(): array
{
return [
'tenant_codigo' => ['required', 'string', 'exists:tenants,codigo'],
'nombre' => ['required', 'string', 'max:255'],
'descripcion' => ['nullable', 'string'],
];

View File

@@ -17,7 +17,6 @@ class StoreCategoryRequest extends FormRequest
public function rules(): array
{
return [
'tenant_code' => ['required_with:categoria_id', 'string', 'exists:tenants,codigo'],
'categoria_id' => ['nullable', 'integer', 'exists:categorias,id'],
'nombre' => ['required', 'string', 'max:255'],
];

View File

@@ -20,13 +20,12 @@ class StoreProductAttributeRequest extends FormRequest
public function rules(): array
{
return [
'tenant_codigo' => ['required', 'string', 'exists:tenants,codigo'],
'codigo' => [
'required',
'string',
'max:255',
Rule::unique('productos_attributes', 'codigo')->where(
fn ($query) => $query->where('tenant_codigo', $this->input('tenant_codigo'))
fn ($query) => $query->where('tenant_codigo', $this->route('tenant')?->codigo)
),
],
'nombre' => ['required', 'string', 'max:255'],

View File

@@ -18,7 +18,6 @@ class StoreProductRequest extends FormRequest
public function rules(): array
{
return [
'tenant_codigo' => ['required', 'string', 'exists:tenants,codigo'],
'categoria_id' => ['required', 'integer'],
'slug' => ['required', 'string', 'max:255', Rule::unique('productos', 'slug')],
'nombre' => ['required', 'string', 'max:255'],

View File

@@ -17,7 +17,6 @@ class UpdateBrandRequest extends FormRequest
public function rules(): array
{
return [
'tenant_codigo' => ['required', 'string', 'exists:tenants,codigo'],
'nombre' => ['required', 'string', 'max:255'],
'descripcion' => ['nullable', 'string'],
];

View File

@@ -22,7 +22,6 @@ class UpdateCategoryRequest extends FormRequest
$category = $this->route('categoria');
return [
'tenant_code' => ['required', 'string', 'exists:tenants,codigo'],
'categoria_id' => [
'nullable',
'integer',

View File

@@ -22,7 +22,6 @@ class UpdateProductRequest extends FormRequest
$product = $this->route('producto');
return [
'tenant_codigo' => ['required', 'string', 'exists:tenants,codigo'],
'categoria_id' => ['required', 'integer'],
'slug' => [
'required',