- Updated the OwnerVerificationRequest model to change pendingToggleIsActive to pendingToggleStatus, reflecting the new status structure. - Refactored the Product model to replace is_active with status, utilizing the ProductStatus enum for better clarity and type safety. - Modified the ProductService to accommodate the new status field, including pagination and creation logic. - Adjusted the AnalysisService to filter products based on their status. - Updated the VerificationChangeFormatter to handle the new status field. - Created a migration to remove is_active from the products table and add status with appropriate default values. - Refactored the ProductSeeder to use the new status field. - Updated frontend components and types to reflect the changes from is_active to status. - Adjusted tests to ensure they validate the new status logic correctly.
69 lines
1.7 KiB
PHP
69 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin\Master;
|
|
|
|
use App\Enums\Permission;
|
|
use App\Enums\ProductStatus;
|
|
use App\Http\Requests\Concerns\HasProductVariantRules;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class ProductRequest extends FormRequest
|
|
{
|
|
use HasProductVariantRules;
|
|
|
|
public function authorize(): bool
|
|
{
|
|
$permission = $this->isMethod('POST')
|
|
? Permission::PRODUCTS_CREATE
|
|
: Permission::PRODUCTS_UPDATE;
|
|
|
|
return $this->user()?->can($permission->value) ?? false;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => ['required', 'string', 'max:200'],
|
|
'description' => ['nullable', 'string'],
|
|
|
|
'category_ids' => ['required', 'array', 'min:1'],
|
|
'category_ids.*' => ['integer', Rule::exists('categories', 'id')->whereNull('deleted_at')],
|
|
|
|
'status' => ['required', 'string', Rule::in(ProductStatus::values())],
|
|
|
|
...$this->productVariantRules(
|
|
productId: $this->route('product')?->id,
|
|
imagesRequired: $this->isMethod('POST'),
|
|
),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'name' => 'nama produk',
|
|
'description' => 'deskripsi',
|
|
'category_ids' => 'kategori',
|
|
'category_ids.*' => 'kategori',
|
|
...$this->productVariantAttributes(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'variants.*.s3_keys.required' => 'Foto varian wajib diisi.',
|
|
];
|
|
}
|
|
}
|