feat: [ItemMaster] ItemPage 생성 시 동일 item_type 중복 방지 로직 추가
- ItemPageService::store()에서 동일 tenant_id + item_type + is_active 조합 중복 검증 - ItemPageStoreRequest에 Rule::unique 검증 추가 (tenant_id 범위 한정) - 에러 메시지 키 추가: error.item_page_duplicate_item_type (ko/en)
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Http\Requests\ItemMaster;
|
||||
|
||||
use App\Models\ItemMaster\ItemPage;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class ItemPageStoreRequest extends FormRequest
|
||||
{
|
||||
@@ -13,10 +15,26 @@ public function authorize(): bool
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$tenantId = app('tenant_id');
|
||||
|
||||
return [
|
||||
'page_name' => 'required|string|max:255',
|
||||
'item_type' => 'required|in:FG,PT,SM,RM,CS',
|
||||
'item_type' => [
|
||||
'required',
|
||||
'in:FG,PT,SM,RM,CS',
|
||||
Rule::unique((new ItemPage)->getTable(), 'item_type')
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('is_active', true)
|
||||
->whereNull('deleted_at'),
|
||||
],
|
||||
'absolute_path' => 'nullable|string|max:500',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'item_type.unique' => __('error.item_page_duplicate_item_type'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,16 @@ public function store(array $data): ItemPage
|
||||
$userId = $this->apiUserId();
|
||||
$itemType = strtoupper($data['item_type']);
|
||||
|
||||
// 동일 tenant_id + item_type 조합의 활성 페이지 중복 검증
|
||||
$exists = ItemPage::where('tenant_id', $tenantId)
|
||||
->where('item_type', $itemType)
|
||||
->where('is_active', true)
|
||||
->exists();
|
||||
|
||||
if ($exists) {
|
||||
throw new BusinessException(__('error.item_page_duplicate_item_type'));
|
||||
}
|
||||
|
||||
// item_type으로 common_codes에서 source_table 조회
|
||||
$sourceTable = $this->getSourceTableFromCommonCode($itemType);
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@
|
||||
'code_exists_in_deleted' => 'The same code exists in deleted data. Please permanently delete that code first or use a different code.',
|
||||
|
||||
// Item type validation
|
||||
'item_page_duplicate_item_type' => 'A page with the same item type already exists.',
|
||||
'item_type_required' => 'Item type (item_type) is required.',
|
||||
'item_type_or_group_required' => 'Item type (item_type) or group ID (group_id) is required.',
|
||||
'invalid_item_type' => 'Invalid item type.',
|
||||
|
||||
@@ -148,6 +148,7 @@
|
||||
'field_key_system_readonly' => '시스템 필드의 field_key는 변경할 수 없습니다.',
|
||||
'field_key_system_cannot_delete' => '시스템 필드는 삭제할 수 없습니다.',
|
||||
'bom_not_found' => 'BOM 항목을 찾을 수 없습니다.',
|
||||
'item_page_duplicate_item_type' => '이미 동일한 품목 유형의 페이지가 존재합니다.',
|
||||
'item_type_required' => '품목 유형(item_type)은 필수입니다.',
|
||||
'item_type_or_group_required' => '품목 유형(item_type) 또는 그룹 ID(group_id)는 필수입니다.',
|
||||
'invalid_item_type' => '유효하지 않은 품목 유형입니다.',
|
||||
|
||||
Reference in New Issue
Block a user