[agent-pipeline] pipe-20260305162146-cqnu round-2
This commit is contained in:
parent
926efe8541
commit
d1b82eb6f8
|
|
@ -3,42 +3,7 @@
|
|||
* 엔드포인트: /api/approval/*
|
||||
*/
|
||||
|
||||
// API URL 동적 설정
|
||||
const getApiBaseUrl = (): string => {
|
||||
if (process.env.NEXT_PUBLIC_API_URL) {
|
||||
return process.env.NEXT_PUBLIC_API_URL;
|
||||
}
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
const currentHost = window.location.hostname;
|
||||
|
||||
if (currentHost === "v1.vexplor.com") {
|
||||
return "https://api.vexplor.com/api";
|
||||
}
|
||||
|
||||
if (currentHost === "localhost" || currentHost === "127.0.0.1") {
|
||||
return "http://localhost:8080/api";
|
||||
}
|
||||
}
|
||||
|
||||
return "/api";
|
||||
};
|
||||
|
||||
const API_BASE = getApiBaseUrl();
|
||||
|
||||
function getAuthToken(): string | null {
|
||||
if (typeof window === "undefined") return null;
|
||||
return localStorage.getItem("authToken") || sessionStorage.getItem("authToken");
|
||||
}
|
||||
|
||||
function getAuthHeaders(): HeadersInit {
|
||||
const token = getAuthToken();
|
||||
const headers: HeadersInit = { "Content-Type": "application/json" };
|
||||
if (token) {
|
||||
(headers as Record<string, string>)["Authorization"] = `Bearer ${token}`;
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
import apiClient from "@/lib/api/client";
|
||||
|
||||
// ============================================================
|
||||
// 공통 타입 정의
|
||||
|
|
@ -196,15 +161,8 @@ export async function getApprovalDefinitions(params?: {
|
|||
search?: string;
|
||||
}): Promise<ApiResponse<ApprovalDefinition[]>> {
|
||||
try {
|
||||
const qs = new URLSearchParams();
|
||||
if (params?.is_active) qs.append("is_active", params.is_active);
|
||||
if (params?.search) qs.append("search", params.search);
|
||||
|
||||
const response = await fetch(
|
||||
`${API_BASE}/approval/definitions${qs.toString() ? `?${qs}` : ""}`,
|
||||
{ headers: getAuthHeaders(), credentials: "include" }
|
||||
);
|
||||
return await response.json();
|
||||
const response = await apiClient.get("/approval/definitions", { params });
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -212,11 +170,8 @@ export async function getApprovalDefinitions(params?: {
|
|||
|
||||
export async function getApprovalDefinition(id: number): Promise<ApiResponse<ApprovalDefinition>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/definitions/${id}`, {
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.get(`/approval/definitions/${id}`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -233,13 +188,8 @@ export async function createApprovalDefinition(data: {
|
|||
is_active?: string;
|
||||
}): Promise<ApiResponse<ApprovalDefinition>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/definitions`, {
|
||||
method: "POST",
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.post("/approval/definitions", data);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -250,13 +200,8 @@ export async function updateApprovalDefinition(
|
|||
data: Partial<ApprovalDefinition>
|
||||
): Promise<ApiResponse<ApprovalDefinition>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/definitions/${id}`, {
|
||||
method: "PUT",
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.put(`/approval/definitions/${id}`, data);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -264,12 +209,8 @@ export async function updateApprovalDefinition(
|
|||
|
||||
export async function deleteApprovalDefinition(id: number): Promise<ApiResponse<void>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/definitions/${id}`, {
|
||||
method: "DELETE",
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.delete(`/approval/definitions/${id}`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -284,15 +225,8 @@ export async function getApprovalTemplates(params?: {
|
|||
is_active?: string;
|
||||
}): Promise<ApiResponse<ApprovalLineTemplate[]>> {
|
||||
try {
|
||||
const qs = new URLSearchParams();
|
||||
if (params?.definition_id) qs.append("definition_id", String(params.definition_id));
|
||||
if (params?.is_active) qs.append("is_active", params.is_active);
|
||||
|
||||
const response = await fetch(
|
||||
`${API_BASE}/approval/templates${qs.toString() ? `?${qs}` : ""}`,
|
||||
{ headers: getAuthHeaders(), credentials: "include" }
|
||||
);
|
||||
return await response.json();
|
||||
const response = await apiClient.get("/approval/templates", { params });
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -300,11 +234,8 @@ export async function getApprovalTemplates(params?: {
|
|||
|
||||
export async function getApprovalTemplate(id: number): Promise<ApiResponse<ApprovalLineTemplate>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/templates/${id}`, {
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.get(`/approval/templates/${id}`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -318,13 +249,8 @@ export async function createApprovalTemplate(data: {
|
|||
steps?: Omit<ApprovalLineTemplateStep, "step_id" | "template_id" | "company_code">[];
|
||||
}): Promise<ApiResponse<ApprovalLineTemplate>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/templates`, {
|
||||
method: "POST",
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.post("/approval/templates", data);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -341,13 +267,8 @@ export async function updateApprovalTemplate(
|
|||
}
|
||||
): Promise<ApiResponse<ApprovalLineTemplate>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/templates/${id}`, {
|
||||
method: "PUT",
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.put(`/approval/templates/${id}`, data);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -355,12 +276,8 @@ export async function updateApprovalTemplate(
|
|||
|
||||
export async function deleteApprovalTemplate(id: number): Promise<ApiResponse<void>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/templates/${id}`, {
|
||||
method: "DELETE",
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.delete(`/approval/templates/${id}`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -380,20 +297,8 @@ export async function getApprovalRequests(params?: {
|
|||
limit?: number;
|
||||
}): Promise<ApiResponse<ApprovalRequest[]>> {
|
||||
try {
|
||||
const qs = new URLSearchParams();
|
||||
if (params?.status) qs.append("status", params.status);
|
||||
if (params?.target_table) qs.append("target_table", params.target_table);
|
||||
if (params?.target_record_id) qs.append("target_record_id", params.target_record_id);
|
||||
if (params?.requester_id) qs.append("requester_id", params.requester_id);
|
||||
if (params?.my_approvals !== undefined) qs.append("my_approvals", String(params.my_approvals));
|
||||
if (params?.page) qs.append("page", String(params.page));
|
||||
if (params?.limit) qs.append("limit", String(params.limit));
|
||||
|
||||
const response = await fetch(
|
||||
`${API_BASE}/approval/requests${qs.toString() ? `?${qs}` : ""}`,
|
||||
{ headers: getAuthHeaders(), credentials: "include" }
|
||||
);
|
||||
return await response.json();
|
||||
const response = await apiClient.get("/approval/requests", { params });
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -401,11 +306,8 @@ export async function getApprovalRequests(params?: {
|
|||
|
||||
export async function getApprovalRequest(id: number): Promise<ApiResponse<ApprovalRequest>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/requests/${id}`, {
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.get(`/approval/requests/${id}`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -415,13 +317,8 @@ export async function createApprovalRequest(
|
|||
data: CreateApprovalRequestInput
|
||||
): Promise<ApiResponse<ApprovalRequest>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/requests`, {
|
||||
method: "POST",
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.post("/approval/requests", data);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -429,12 +326,8 @@ export async function createApprovalRequest(
|
|||
|
||||
export async function cancelApprovalRequest(id: number): Promise<ApiResponse<void>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/requests/${id}/cancel`, {
|
||||
method: "POST",
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.post(`/approval/requests/${id}/cancel`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -446,11 +339,8 @@ export async function cancelApprovalRequest(id: number): Promise<ApiResponse<voi
|
|||
|
||||
export async function getMyPendingApprovals(): Promise<ApiResponse<ApprovalLine[]>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/my-pending`, {
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.get("/approval/my-pending");
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -461,13 +351,8 @@ export async function processApprovalLine(
|
|||
data: { action: "approved" | "rejected"; comment?: string }
|
||||
): Promise<ApiResponse<void>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/lines/${lineId}/process`, {
|
||||
method: "POST",
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.post(`/approval/lines/${lineId}/process`, data);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -479,11 +364,8 @@ export async function processApprovalLine(
|
|||
|
||||
export async function getProxySettings(): Promise<ApiResponse<ApprovalProxySetting[]>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/proxy-settings`, {
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.get("/approval/proxy-settings");
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -497,13 +379,8 @@ export async function createProxySetting(data: {
|
|||
reason?: string;
|
||||
}): Promise<ApiResponse<ApprovalProxySetting>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/proxy-settings`, {
|
||||
method: "POST",
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.post("/approval/proxy-settings", data);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -520,13 +397,8 @@ export async function updateProxySetting(
|
|||
}
|
||||
): Promise<ApiResponse<ApprovalProxySetting>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/proxy-settings/${id}`, {
|
||||
method: "PUT",
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.put(`/approval/proxy-settings/${id}`, data);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -534,12 +406,8 @@ export async function updateProxySetting(
|
|||
|
||||
export async function deleteProxySetting(id: number): Promise<ApiResponse<void>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/proxy-settings/${id}`, {
|
||||
method: "DELETE",
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.delete(`/approval/proxy-settings/${id}`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -549,11 +417,10 @@ export async function checkActiveProxy(
|
|||
userId: string
|
||||
): Promise<ApiResponse<{ proxy_user_id: string; proxy_user_name?: string } | null>> {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${API_BASE}/approval/proxy-settings/check/${encodeURIComponent(userId)}`,
|
||||
{ headers: getAuthHeaders(), credentials: "include" }
|
||||
const response = await apiClient.get(
|
||||
`/approval/proxy-settings/check/${encodeURIComponent(userId)}`
|
||||
);
|
||||
return await response.json();
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -565,12 +432,8 @@ export async function checkActiveProxy(
|
|||
|
||||
export async function postApproveRequest(requestId: number): Promise<ApiResponse<void>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/requests/${requestId}/post-approve`, {
|
||||
method: "POST",
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.post(`/approval/requests/${requestId}/post-approve`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -584,11 +447,8 @@ export async function getTemplateSteps(
|
|||
templateId: number
|
||||
): Promise<ApiResponse<ApprovalLineTemplateStep[]>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/templates/${templateId}/steps`, {
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.get(`/approval/templates/${templateId}/steps`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -599,13 +459,8 @@ export async function createTemplateStep(
|
|||
data: Omit<ApprovalLineTemplateStep, "step_id" | "template_id" | "company_code">
|
||||
): Promise<ApiResponse<ApprovalLineTemplateStep>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/templates/${templateId}/steps`, {
|
||||
method: "POST",
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.post(`/approval/templates/${templateId}/steps`, data);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -617,13 +472,11 @@ export async function updateTemplateStep(
|
|||
data: Partial<Omit<ApprovalLineTemplateStep, "step_id" | "template_id" | "company_code">>
|
||||
): Promise<ApiResponse<ApprovalLineTemplateStep>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/templates/${templateId}/steps/${stepId}`, {
|
||||
method: "PUT",
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.put(
|
||||
`/approval/templates/${templateId}/steps/${stepId}`,
|
||||
data
|
||||
);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
@ -634,12 +487,10 @@ export async function deleteTemplateStep(
|
|||
stepId: number
|
||||
): Promise<ApiResponse<void>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/approval/templates/${templateId}/steps/${stepId}`, {
|
||||
method: "DELETE",
|
||||
headers: getAuthHeaders(),
|
||||
credentials: "include",
|
||||
});
|
||||
return await response.json();
|
||||
const response = await apiClient.delete(
|
||||
`/approval/templates/${templateId}/steps/${stepId}`
|
||||
);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue