summaryrefslogtreecommitdiff
path: root/lib/items-tech/service.ts
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-07-24 11:06:32 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-07-24 11:06:32 +0000
commit1dc24d48e52f2e490f5603ceb02842586ecae533 (patch)
tree8fca2c5b5b52cc10557b5ba6e55b937ae3c57cf6 /lib/items-tech/service.ts
parented0d6fcc98f671280c2ccde797b50693da88152e (diff)
(대표님) 정기평가 피드백 반영, 설계 피드백 반영, (최겸) 기술영업 피드백 반영
Diffstat (limited to 'lib/items-tech/service.ts')
-rw-r--r--lib/items-tech/service.ts42
1 files changed, 32 insertions, 10 deletions
diff --git a/lib/items-tech/service.ts b/lib/items-tech/service.ts
index d93c5f96..e0896144 100644
--- a/lib/items-tech/service.ts
+++ b/lib/items-tech/service.ts
@@ -14,7 +14,7 @@ import { itemShipbuilding, itemOffshoreTop, itemOffshoreHull } from "@/db/schema
// 타입 정의 추가
export type ShipbuildingWorkType = '기장' | '전장' | '선실' | '배관' | '철의' | '선체';
-export type OffshoreTopWorkType = 'TM' | 'TS' | 'TE' | 'TP';
+export type OffshoreTopWorkType = 'TM' | 'TS' | 'TE' | 'TP' | 'TA';
export type OffshoreHullWorkType = 'HA' | 'HE' | 'HH' | 'HM' | 'HO' | 'HP' | 'NC';
export interface ShipbuildingItem {
@@ -415,6 +415,27 @@ export async function createShipbuildingItem(input: TypedItemCreateData) {
}
const shipData = input as ShipbuildingItemCreateData;
+
+ // 아이템코드 + 선종 조합으로 중복 체크
+ if (input.itemCode && shipData.shipTypes) {
+ const existingItem = await db.select().from(itemShipbuilding)
+ .where(
+ and(
+ eq(itemShipbuilding.itemCode, input.itemCode),
+ eq(itemShipbuilding.shipTypes, shipData.shipTypes)
+ )
+ );
+
+ if (existingItem.length > 0) {
+ return {
+ success: false,
+ message: "중복된 아이템코드 및 선종입니다",
+ data: null,
+ error: "중복 키 오류"
+ }
+ }
+ }
+
const result = await db.insert(itemShipbuilding).values({
itemCode: input.itemCode || "",
workType: shipData.workType ? (shipData.workType as '기장' | '전장' | '선실' | '배관' | '철의' | '선체') : '기장',
@@ -437,7 +458,7 @@ export async function createShipbuildingItem(input: TypedItemCreateData) {
if (err instanceof Error && err.message.includes("unique constraint")) {
return {
success: false,
- message: "이미 존재하는 아이템 코드입니다",
+ message: "중복된 아이템코드 및 선종입니다",
data: null,
error: "중복 키 오류"
}
@@ -488,7 +509,7 @@ export async function createShipbuildingImportItem(input: {
if (existingItem.length > 0) {
return {
success: false,
- message: "이미 존재하는 아이템 코드 및 선종입니다",
+ message: "중복된 아이템코드 및 선종입니다",
data: null,
error: "중복 키 오류"
}
@@ -517,7 +538,7 @@ export async function createShipbuildingImportItem(input: {
if (err instanceof Error && err.message.includes("unique constraint")) {
return {
success: false,
- message: "이미 존재하는 아이템 코드 및 선종입니다",
+ message: "중복된 아이템코드 및 선종입니다",
data: null,
error: "중복 키 오류"
}
@@ -557,7 +578,7 @@ export async function createOffshoreTopItem(data: OffshoreTopItemCreateData) {
if (existingItem.length > 0) {
return {
success: false,
- message: "이미 존재하는 아이템 코드입니다",
+ message: "중복된 아이템 코드입니다",
data: null,
error: "중복 키 오류"
};
@@ -586,7 +607,7 @@ export async function createOffshoreTopItem(data: OffshoreTopItemCreateData) {
if (err instanceof Error && err.message.includes("unique constraint")) {
return {
success: false,
- message: "이미 존재하는 아이템 코드입니다",
+ message: "중복된 아이템 코드입니다",
data: null,
error: "중복 키 오류"
};
@@ -626,7 +647,7 @@ export async function createOffshoreHullItem(data: OffshoreHullItemCreateData) {
if (existingItem.length > 0) {
return {
success: false,
- message: "이미 존재하는 아이템 코드입니다",
+ message: "중복된 아이템 코드입니다",
data: null,
error: "중복 키 오류"
};
@@ -655,7 +676,7 @@ export async function createOffshoreHullItem(data: OffshoreHullItemCreateData) {
if (err instanceof Error && err.message.includes("unique constraint")) {
return {
success: false,
- message: "이미 존재하는 아이템 코드입니다",
+ message: "중복된 아이템 코드입니다",
data: null,
error: "중복 키 오류"
};
@@ -735,7 +756,7 @@ export async function modifyOffshoreTopItem(input: UpdateOffshoreTopItemInput) {
try {
const updateData: Record<string, unknown> = {};
- if (input.workType) updateData.workType = input.workType as 'TM' | 'TS' | 'TE' | 'TP';
+ if (input.workType) updateData.workType = input.workType as 'TM' | 'TS' | 'TE' | 'TP' | 'TA';
if (input.itemList !== undefined) updateData.itemList = input.itemList;
if (input.subItemList !== undefined) updateData.subItemList = input.subItemList;
if (input.itemCode) updateData.itemCode = input.itemCode;
@@ -781,7 +802,7 @@ export async function modifyOffshoreHullItem(input: UpdateOffshoreHullItemInput)
try {
const updateData: Record<string, unknown> = {};
- if (input.workType) updateData.workType = input.workType as 'HA' | 'HE' | 'HH' | 'HM' | 'NC';
+ if (input.workType) updateData.workType = input.workType as 'HA' | 'HE' | 'HH' | 'HM' | 'HO' | 'HP' | 'NC';
if (input.itemList !== undefined) updateData.itemList = input.itemList;
if (input.subItemList !== undefined) updateData.subItemList = input.subItemList;
if (input.itemCode) updateData.itemCode = input.itemCode;
@@ -1222,6 +1243,7 @@ export async function getOffshoreTopWorkTypes() {
{ code: 'TS' as OffshoreTopWorkType, name: 'TS'},
{ code: 'TE' as OffshoreTopWorkType, name: 'TE'},
{ code: 'TP' as OffshoreTopWorkType, name: 'TP'},
+ { code: 'TA' as OffshoreTopWorkType, name: 'TA'},
]
}