diff options
| author | joonhoekim <26rote@gmail.com> | 2025-08-22 02:18:10 +0000 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-08-22 02:18:10 +0000 |
| commit | bde9151154dc9731046ac3facdc4869b7612a7af (patch) | |
| tree | a9b8337114e101cce92c97a05e2b0ded12da4809 /lib/forms/sedp-actions.ts | |
| parent | 7dd2b9fc1856306652f311d19697d9880955bfab (diff) | |
(김준회) 설계 데이터 입력 - EDP 에 클라이언트가 직접 요청 보내던 문제 수정
Diffstat (limited to 'lib/forms/sedp-actions.ts')
| -rw-r--r-- | lib/forms/sedp-actions.ts | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/lib/forms/sedp-actions.ts b/lib/forms/sedp-actions.ts new file mode 100644 index 00000000..24ae2e66 --- /dev/null +++ b/lib/forms/sedp-actions.ts @@ -0,0 +1,116 @@ +"use server"; + +import { getSEDPToken } from "@/lib/sedp/sedp-token"; + +interface SEDPTagData { + [tableName: string]: Array<{ + TAG_NO: string; + TAG_DESC: string; + ATTRIBUTES: Array<{ + ATT_ID: string; + VALUE: string; + }>; + }>; +} + +interface SEDPTemplateData { + templateId: string; + content: string; + projectNo: string; + regTypeId: string; + [key: string]: any; +} + +/** + * SEDP에서 태그 데이터를 가져오는 서버 액션 + */ +export async function fetchTagDataFromSEDP( + projectCode: string, + formCode: string +): Promise<SEDPTagData> { + try { + // Get the token + const apiKey = await getSEDPToken(); + + // Define the API base URL + const SEDP_API_BASE_URL = process.env.SEDP_API_BASE_URL || 'http://sedpwebapi.ship.samsung.co.kr/api'; + + // Make the API call + const response = await fetch( + `${SEDP_API_BASE_URL}/Data/GetPubData`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'accept': '*/*', + 'ApiKey': apiKey, + 'ProjectNo': projectCode + }, + body: JSON.stringify({ + ProjectNo: projectCode, + REG_TYPE_ID: formCode, + ContainDeleted: false + }) + } + ); + + if (!response.ok) { + const errorText = await response.text(); + throw new Error(`SEDP API request failed: ${response.status} ${response.statusText} - ${errorText}`); + } + + const data = await response.json(); + return data as SEDPTagData; + } catch (error: unknown) { + console.error('Error calling SEDP API:', error); + const errorMessage = error instanceof Error ? error.message : 'Unknown error'; + throw new Error(`Failed to fetch data from SEDP API: ${errorMessage}`); + } +} + +/** + * SEDP에서 템플릿 데이터를 가져오는 서버 액션 + */ +export async function fetchTemplateFromSEDP( + projectCode: string, + formCode: string +): Promise<SEDPTemplateData> { + try { + // Get the token + const apiKey = await getSEDPToken(); + + // Define the API base URL + const SEDP_API_BASE_URL = process.env.SEDP_API_BASE_URL || 'http://sedpwebapi.ship.samsung.co.kr/api'; + + // Make the API call + const response = await fetch( + `${SEDP_API_BASE_URL}/Template/GetByRegisterID`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'accept': '*/*', + 'ApiKey': apiKey, + 'ProjectNo': projectCode + }, + body: JSON.stringify({ + WithContent: true, + ProjectNo: projectCode, + REG_TYPE_ID: formCode + }) + } + ); + + if (!response.ok) { + const errorText = await response.text(); + throw new Error(`SEDP Template API request failed: ${response.status} ${response.statusText} - ${errorText}`); + } + + const data = await response.json(); + return data as SEDPTemplateData; + } catch (error: unknown) { + console.error('Error calling SEDP Template API:', error); + const errorMessage = error instanceof Error ? error.message : 'Unknown error'; + throw new Error(`Failed to fetch template from SEDP API: ${errorMessage}`); + } +} |
