diff options
| author | joonhoekim <26rote@gmail.com> | 2025-09-22 18:59:13 +0900 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-09-22 18:59:13 +0900 |
| commit | ba35e67845f935c8ce0151c9ef1fefa0b0510faf (patch) | |
| tree | d05eb27fab2acc54a839b2590c89e860d58fb747 /lib/avl/service.ts | |
| parent | e4bd037d158513e45373ad9e1ef13f71af12162a (diff) | |
(김준회) AVL 피드백 반영 (이진용 프로 건)
Diffstat (limited to 'lib/avl/service.ts')
| -rw-r--r-- | lib/avl/service.ts | 117 |
1 files changed, 116 insertions, 1 deletions
diff --git a/lib/avl/service.ts b/lib/avl/service.ts index 3d188f85..0340f52c 100644 --- a/lib/avl/service.ts +++ b/lib/avl/service.ts @@ -552,7 +552,7 @@ export async function createAvlList(data: CreateAvlListInput): Promise<AvlListIt debugSuccess('DB INSERT 완료', { table: 'avl_list', result: result[0], - savedSnapshotLength: result[0].vendorInfoSnapshot?.length + savedSnapshotLength: Array.isArray((result[0] as any).vendorInfoSnapshot) ? (result[0] as any).vendorInfoSnapshot.length : 0 }); const createdItem = result[0]; @@ -800,6 +800,27 @@ export async function createAvlVendorInfo(data: AvlVendorInfoInput): Promise<Avl return transformedData; } catch (err) { debugError('AVL Vendor Info 생성 실패', { error: err, inputData: data }); + + // unique 제약조건 위반 에러 처리 + if (err instanceof Error) { + if (err.message.includes('unique_standard_avl_material_vendor')) { + console.error("Unique constraint violation (standard AVL):", err.message); + // 사용자에게는 친화적인 메시지를 보여주기 위해 null 반환 + // 실제 애플리케이션에서는 이 에러를 catch해서 적절한 메시지 표시 + return null; + } + + if (err.message.includes('unique_project_avl_material_vendor')) { + console.error("Unique constraint violation (project AVL):", err.message); + return null; + } + + if (err.message.includes('duplicate key value violates unique constraint')) { + console.error("Unique constraint violation:", err.message); + return null; + } + } + console.error("Error in createAvlVendorInfo:", err); return null; } @@ -1559,6 +1580,24 @@ export const copyToProjectAvl = async ( } catch (error) { debugError('선종별표준AVL → 프로젝트AVL 복사 실패', { error, selectedIds, targetProjectCode }); + + // unique 제약조건 위반 에러 처리 + if (error instanceof Error) { + if (error.message.includes('unique_project_avl_material_vendor')) { + return { + success: false, + message: "선택한 항목 중 이미 존재하는 [자재그룹코드 + 협력업체명] 조합이 있어 복사할 수 없습니다. 중복되지 않는 항목만 선택해주세요." + }; + } + + if (error.message.includes('duplicate key value violates unique constraint')) { + return { + success: false, + message: "중복 데이터로 인해 복사할 수 없습니다. 이미 존재하는 데이터와 중복되지 않는 항목만 선택해주세요." + }; + } + } + return { success: false, message: "프로젝트 AVL로 복사 중 오류가 발생했습니다." @@ -1646,6 +1685,24 @@ export const copyToStandardAvl = async ( } catch (error) { debugError('프로젝트AVL → 선종별표준AVL 복사 실패', { error, selectedIds, targetStandardInfo }); + + // unique 제약조건 위반 에러 처리 + if (error instanceof Error) { + if (error.message.includes('unique_standard_avl_material_vendor')) { + return { + success: false, + message: "선택한 항목 중 해당 표준AVL에 이미 존재하는 [자재그룹코드 + 협력업체명] 조합이 있어 복사할 수 없습니다. 중복되지 않는 항목만 선택해주세요." + }; + } + + if (error.message.includes('duplicate key value violates unique constraint')) { + return { + success: false, + message: "중복 데이터로 인해 복사할 수 없습니다. 이미 존재하는 데이터와 중복되지 않는 항목만 선택해주세요." + }; + } + } + return { success: false, message: "선종별표준AVL로 복사 중 오류가 발생했습니다." @@ -1812,6 +1869,17 @@ export const copyToVendorPool = async ( } catch (error) { debugError('프로젝트AVL → 벤더풀 복사 실패', { error, selectedIds }); + + // unique 제약조건 위반 에러 처리 (벤더풀에는 다른 unique 제약조건이 있을 수 있음) + if (error instanceof Error) { + if (error.message.includes('duplicate key value violates unique constraint')) { + return { + success: false, + message: "중복 데이터로 인해 벤더풀로 복사할 수 없습니다. 이미 존재하는 데이터와 중복되지 않는 항목만 선택해주세요." + }; + } + } + return { success: false, message: "벤더풀로 복사 중 오류가 발생했습니다." @@ -1931,6 +1999,24 @@ export const copyFromVendorPoolToProjectAvl = async ( } catch (error) { debugError('벤더풀 → 프로젝트AVL 복사 실패', { error, selectedIds, targetProjectCode }); + + // unique 제약조건 위반 에러 처리 + if (error instanceof Error) { + if (error.message.includes('unique_project_avl_material_vendor')) { + return { + success: false, + message: "선택한 항목 중 해당 프로젝트에 이미 존재하는 [자재그룹코드 + 협력업체명] 조합이 있어 복사할 수 없습니다. 중복되지 않는 항목만 선택해주세요." + }; + } + + if (error.message.includes('duplicate key value violates unique constraint')) { + return { + success: false, + message: "중복 데이터로 인해 복사할 수 없습니다. 이미 존재하는 데이터와 중복되지 않는 항목만 선택해주세요." + }; + } + } + return { success: false, message: "프로젝트 AVL로 복사 중 오류가 발생했습니다." @@ -2055,6 +2141,24 @@ export const copyFromVendorPoolToStandardAvl = async ( } catch (error) { debugError('벤더풀 → 선종별표준AVL 복사 실패', { error, selectedIds, targetStandardInfo }); + + // unique 제약조건 위반 에러 처리 + if (error instanceof Error) { + if (error.message.includes('unique_standard_avl_material_vendor')) { + return { + success: false, + message: "선택한 항목 중 해당 표준AVL에 이미 존재하는 [자재그룹코드 + 협력업체명] 조합이 있어 복사할 수 없습니다. 중복되지 않는 항목만 선택해주세요." + }; + } + + if (error.message.includes('duplicate key value violates unique constraint')) { + return { + success: false, + message: "중복 데이터로 인해 복사할 수 없습니다. 이미 존재하는 데이터와 중복되지 않는 항목만 선택해주세요." + }; + } + } + return { success: false, message: "선종별표준AVL로 복사 중 오류가 발생했습니다." @@ -2213,6 +2317,17 @@ export const copyFromStandardAvlToVendorPool = async ( } catch (error) { debugError('선종별표준AVL → 벤더풀 복사 실패', { error, selectedIds }); + + // unique 제약조건 위반 에러 처리 (벤더풀에는 다른 unique 제약조건이 있을 수 있음) + if (error instanceof Error) { + if (error.message.includes('duplicate key value violates unique constraint')) { + return { + success: false, + message: "중복 데이터로 인해 벤더풀로 복사할 수 없습니다. 이미 존재하는 데이터와 중복되지 않는 항목만 선택해주세요." + }; + } + } + return { success: false, message: "벤더풀로 복사 중 오류가 발생했습니다." |
