diff options
| author | joonhoekim <26rote@gmail.com> | 2025-07-01 10:45:37 +0000 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-07-01 10:45:37 +0000 |
| commit | 4fb273b7fc85352183113f1240fc33f7d6c98328 (patch) | |
| tree | 420302b9edec72cd153b3fa1791c4a55e041616b /lib/vendors/mdg-actions.ts | |
| parent | 6e25ab8da8a90a6d9bf40ccc83e36f119fb27568 (diff) | |
(김준회) 벤더 기본 정보 UI 및 서비스 - NONSAP 에서 데이터 페칭
Diffstat (limited to 'lib/vendors/mdg-actions.ts')
| -rw-r--r-- | lib/vendors/mdg-actions.ts | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/lib/vendors/mdg-actions.ts b/lib/vendors/mdg-actions.ts new file mode 100644 index 00000000..ac57aec4 --- /dev/null +++ b/lib/vendors/mdg-actions.ts @@ -0,0 +1,93 @@ +"use server" + +/** + * MDG 마이그레이션 진행되지 않은 상태라 PLM DB를 싱크해 사용했으므로, 추후 수정 필요 + * PLM 쪽으로는 업데이트 불가능하므로, 최초 1회 마이그레이션한 데이터만 사용할 것임 + * node-cron 으로 PLM 데이터 동기화할 필요도 없다는 얘기 + */ + +import { revalidateTag } from "next/cache" +import { vendorMdgService, type VendorUpdateData } from "./mdg-service" +import { z } from "zod" + +// 벤더 업데이트 데이터 스키마 +const vendorUpdateSchema = z.object({ + vendorId: z.string().min(1, "Vendor ID is required"), + updateData: z.object({ + VNDRNM_1: z.string().optional(), + VNDRNM_2: z.string().optional(), + VNDRNM_ABRV_1: z.string().optional(), + BIZR_NO: z.string().optional(), + CO_REG_NO: z.string().optional(), + CO_VLM: z.string().optional(), + REPR_NM: z.string().optional(), + REP_TEL_NO: z.string().optional(), + REPR_RESNO: z.string().optional(), + REPRESENTATIVE_EMAIL: z.string().optional(), + BIZTP: z.string().optional(), + BIZCON: z.string().optional(), + NTN_CD: z.string().optional(), + ADR_1: z.string().optional(), + ADR_2: z.string().optional(), + POSTAL_CODE: z.string().optional(), + ADDR_DETAIL_1: z.string().optional(), + }) +}) + +export type VendorUpdateInput = z.infer<typeof vendorUpdateSchema> + +/** + * MDG 벤더 기본 정보 업데이트 서버 액션 + */ +export async function updateMdgVendorBasicInfo(input: VendorUpdateInput) { + try { + // 입력 데이터 검증 + const validatedData = vendorUpdateSchema.parse(input) + + // 벤더 ID로 벤더 코드 조회 + const vendorCode = await vendorMdgService.getVendorCodeByVendorId(validatedData.vendorId) + + if (!vendorCode) { + return { + success: false, + error: "벤더를 찾을 수 없습니다." + } + } + + // MDG 서비스를 통해 벤더 정보 업데이트 + const success = await vendorMdgService.updateVendorBasicInfo( + vendorCode, + validatedData.updateData + ) + + if (success) { + // 캐시 무효화 + revalidateTag(`vendor-details-${validatedData.vendorId}`) + revalidateTag("vendors") + + return { + success: true, + message: "벤더 정보가 성공적으로 업데이트되었습니다." + } + } else { + return { + success: false, + error: "벤더 정보 업데이트에 실패했습니다." + } + } + } catch (error) { + console.error("MDG 벤더 정보 업데이트 중 오류:", error) + + if (error instanceof z.ZodError) { + return { + success: false, + error: `입력 데이터 오류: ${error.errors[0].message}` + } + } + + return { + success: false, + error: error instanceof Error ? error.message : "알 수 없는 오류가 발생했습니다." + } + } +}
\ No newline at end of file |
