fix(API): 공통코드 조회 테넌트 분리 - 글로벌 폴백 적용
- 테넌트 데이터 존재 시 테넌트만 조회, 없으면 글로벌 폴백 - 기존: tenant OR NULL → 글로벌+테넌트 중복 반환 문제 해결 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -36,13 +36,23 @@ public function index(Request $request, string $group)
|
||||
return ApiResponse::handle(function () use ($group) {
|
||||
$tenantId = app('tenant_id');
|
||||
|
||||
// 테넌트 전용 데이터가 있으면 테넌트만, 없으면 글로벌 폴백
|
||||
$tenantCount = DB::table('common_codes')
|
||||
->where('code_group', $group)
|
||||
->where('is_active', true)
|
||||
->where('tenant_id', $tenantId)
|
||||
->count();
|
||||
|
||||
return DB::table('common_codes')
|
||||
->select(['id', 'code', 'name', 'description', 'sort_order', 'attributes'])
|
||||
->where('code_group', $group)
|
||||
->where('is_active', true)
|
||||
->where(function ($query) use ($tenantId) {
|
||||
$query->where('tenant_id', $tenantId)
|
||||
->orWhereNull('tenant_id');
|
||||
->where(function ($query) use ($tenantId, $tenantCount) {
|
||||
if ($tenantCount > 0) {
|
||||
$query->where('tenant_id', $tenantId);
|
||||
} else {
|
||||
$query->whereNull('tenant_id');
|
||||
}
|
||||
})
|
||||
->orderBy('sort_order')
|
||||
->get();
|
||||
|
||||
Reference in New Issue
Block a user