summaryrefslogtreecommitdiff
path: root/lib/forms/sedp-actions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/forms/sedp-actions.ts')
-rw-r--r--lib/forms/sedp-actions.ts59
1 files changed, 47 insertions, 12 deletions
diff --git a/lib/forms/sedp-actions.ts b/lib/forms/sedp-actions.ts
index 24ae2e66..d20fb9fc 100644
--- a/lib/forms/sedp-actions.ts
+++ b/lib/forms/sedp-actions.ts
@@ -74,7 +74,7 @@ export async function fetchTagDataFromSEDP(
export async function fetchTemplateFromSEDP(
projectCode: string,
formCode: string
-): Promise<SEDPTemplateData> {
+): Promise<SEDPTemplateData[]> {
try {
// Get the token
const apiKey = await getSEDPToken();
@@ -82,9 +82,8 @@ export async function fetchTemplateFromSEDP(
// 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`,
+ const responseAdapter = await fetch(
+ `${SEDP_API_BASE_URL}/AdapterDataMapping/GetByToolID`,
{
method: 'POST',
headers: {
@@ -94,23 +93,59 @@ export async function fetchTemplateFromSEDP(
'ProjectNo': projectCode
},
body: JSON.stringify({
- WithContent: true,
ProjectNo: projectCode,
- REG_TYPE_ID: formCode
+ "TOOL_ID": "eVCP"
})
}
);
- if (!response.ok) {
- const errorText = await response.text();
- throw new Error(`SEDP Template API request failed: ${response.status} ${response.statusText} - ${errorText}`);
+ if (!responseAdapter.ok) {
+ throw new Error(`새 레지스터 요청 실패: ${responseAdapter.status} ${responseAdapter.statusText}`);
}
- const data = await response.json();
- return data as SEDPTemplateData;
+ const dataAdapter = await responseAdapter.json();
+ const templateList = dataAdapter.find(v => v.REG_TYPE_ID === formCode)?.MAP_TMPLS || [];
+
+ // 각 TMPL_ID에 대해 API 호출
+ const templatePromises = templateList.map(async (tmplId: string) => {
+ const response = await fetch(
+ `${SEDP_API_BASE_URL}/Template/GetByID`,
+ {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'accept': '*/*',
+ 'ApiKey': apiKey,
+ 'ProjectNo': projectCode
+ },
+ body: JSON.stringify({
+ WithContent: true,
+ ProjectNo: projectCode,
+ TMPL_ID: tmplId
+ })
+ }
+ );
+
+ if (!response.ok) {
+ const errorText = await response.text();
+ throw new Error(`SEDP Template API request failed for TMPL_ID ${tmplId}: ${response.status} ${response.statusText} - ${errorText}`);
+ }
+
+ const data = await response.json();
+ return data as SEDPTemplateData;
+ });
+
+ // 모든 API 호출을 병렬로 실행하고 결과를 수집
+ const templates = await Promise.all(templatePromises);
+
+ // null이나 undefined가 아닌 값들만 필터링 (응답이 없는 경우 제외)
+ const validTemplates = templates.filter(template => template != null);
+
+ return validTemplates;
+
} 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}`);
}
-}
+} \ No newline at end of file