fix: ItemPage 생성 시 source_table 자동 설정

- store() 메서드에서 item_type으로 common_codes.attributes의 source_table 조회
- getSourceTableFromCommonCode() 헬퍼 메서드 추가
- 기존 source_table이 null인 레코드 수정 (tenant_id=288의 CS, RM)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-26 13:49:43 +09:00
parent 1f5539db32
commit 5ab5353d4d

View File

@@ -43,11 +43,16 @@ public function store(array $data): ItemPage
{
$tenantId = $this->tenantId();
$userId = $this->apiUserId();
$itemType = strtoupper($data['item_type']);
// item_type으로 common_codes에서 source_table 조회
$sourceTable = $this->getSourceTableFromCommonCode($itemType);
$page = ItemPage::create([
'tenant_id' => $tenantId,
'page_name' => $data['page_name'],
'item_type' => $data['item_type'],
'item_type' => $itemType,
'source_table' => $sourceTable,
'absolute_path' => $data['absolute_path'] ?? null,
'is_active' => true,
'created_by' => $userId,
@@ -127,4 +132,23 @@ public function destroy(int $id): void
$page->update(['deleted_by' => $userId]);
$page->delete();
}
/**
* item_type에 해당하는 source_table을 common_codes.attributes에서 조회
*/
private function getSourceTableFromCommonCode(string $itemType): ?string
{
$commonCode = \DB::table('common_codes')
->where('code_group', 'item_type')
->where('code', strtoupper($itemType))
->first();
if (! $commonCode || ! $commonCode->attributes) {
return null;
}
$attrs = json_decode($commonCode->attributes, true);
return $attrs['source_table'] ?? null;
}
}