- 모든 라우트에 인증 미들웨어를 적용하여 보안을 강화하였습니다. - 화면 그룹 삭제 시 회사 코드 확인 및 권한 체크 로직을 추가하여, 다른 회사의 그룹 삭제를 방지하였습니다. - 채번 규칙, 카테고리 값, 테이블 타입 컬럼 복제 시 같은 회사로 복제하는 경우 경고 메시지를 추가하였습니다. - 메뉴 URL 업데이트 기능을 추가하여 복제된 화면 ID에 맞게 URL을 재매핑하도록 하였습니다.
209 lines
5.7 KiB
TypeScript
209 lines
5.7 KiB
TypeScript
/**
|
|
* 카테고리 트리 API 클라이언트 (테스트용)
|
|
* - 트리 구조 CRUD 지원
|
|
*/
|
|
|
|
import { apiClient } from "./client";
|
|
|
|
// 카테고리 값 타입
|
|
export interface CategoryValue {
|
|
valueId: number;
|
|
tableName: string;
|
|
columnName: string;
|
|
valueCode: string;
|
|
valueLabel: string;
|
|
valueOrder: number;
|
|
parentValueId: number | null;
|
|
depth: number; // 1=대분류, 2=중분류, 3=소분류
|
|
path: string | null;
|
|
description: string | null;
|
|
color: string | null;
|
|
icon: string | null;
|
|
isActive: boolean;
|
|
isDefault: boolean;
|
|
companyCode: string;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
// 트리 구조용
|
|
children?: CategoryValue[];
|
|
}
|
|
|
|
// 카테고리 값 생성 입력
|
|
export interface CreateCategoryValueInput {
|
|
tableName: string;
|
|
columnName: string;
|
|
valueCode: string;
|
|
valueLabel: string;
|
|
valueOrder?: number;
|
|
parentValueId?: number | null;
|
|
description?: string;
|
|
color?: string;
|
|
icon?: string;
|
|
isActive?: boolean;
|
|
isDefault?: boolean;
|
|
targetCompanyCode?: string; // 저장할 회사 코드 (최고 관리자가 회사 선택 시)
|
|
}
|
|
|
|
// 카테고리 값 수정 입력
|
|
export interface UpdateCategoryValueInput {
|
|
valueCode?: string;
|
|
valueLabel?: string;
|
|
valueOrder?: number;
|
|
parentValueId?: number | null;
|
|
description?: string;
|
|
color?: string;
|
|
icon?: string;
|
|
isActive?: boolean;
|
|
isDefault?: boolean;
|
|
}
|
|
|
|
// API 응답 타입
|
|
export interface ApiResponse<T> {
|
|
success: boolean;
|
|
data?: T;
|
|
error?: string;
|
|
message?: string;
|
|
}
|
|
|
|
/**
|
|
* 카테고리 트리 조회
|
|
*/
|
|
export async function getCategoryTree(
|
|
tableName: string,
|
|
columnName: string
|
|
): Promise<ApiResponse<CategoryValue[]>> {
|
|
try {
|
|
const response = await apiClient.get(`/category-tree/test/${tableName}/${columnName}`);
|
|
return response.data;
|
|
} catch (error: unknown) {
|
|
const err = error as { response?: { data?: { error?: string } }; message?: string };
|
|
return {
|
|
success: false,
|
|
error: err.response?.data?.error || err.message || "카테고리 트리 조회 실패",
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 카테고리 목록 조회 (플랫)
|
|
*/
|
|
export async function getCategoryList(
|
|
tableName: string,
|
|
columnName: string
|
|
): Promise<ApiResponse<CategoryValue[]>> {
|
|
try {
|
|
const response = await apiClient.get(`/category-tree/test/${tableName}/${columnName}/flat`);
|
|
return response.data;
|
|
} catch (error: unknown) {
|
|
const err = error as { response?: { data?: { error?: string } }; message?: string };
|
|
return {
|
|
success: false,
|
|
error: err.response?.data?.error || err.message || "카테고리 목록 조회 실패",
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 카테고리 값 단일 조회
|
|
*/
|
|
export async function getCategoryValue(valueId: number): Promise<ApiResponse<CategoryValue>> {
|
|
try {
|
|
const response = await apiClient.get(`/category-tree/test/value/${valueId}`);
|
|
return response.data;
|
|
} catch (error: unknown) {
|
|
const err = error as { response?: { data?: { error?: string } }; message?: string };
|
|
return {
|
|
success: false,
|
|
error: err.response?.data?.error || err.message || "카테고리 값 조회 실패",
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 카테고리 값 생성
|
|
*/
|
|
export async function createCategoryValue(
|
|
input: CreateCategoryValueInput
|
|
): Promise<ApiResponse<CategoryValue>> {
|
|
try {
|
|
const response = await apiClient.post("/category-tree/test/value", input);
|
|
return response.data;
|
|
} catch (error: unknown) {
|
|
const err = error as { response?: { data?: { error?: string } }; message?: string };
|
|
return {
|
|
success: false,
|
|
error: err.response?.data?.error || err.message || "카테고리 값 생성 실패",
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 카테고리 값 수정
|
|
*/
|
|
export async function updateCategoryValue(
|
|
valueId: number,
|
|
input: UpdateCategoryValueInput
|
|
): Promise<ApiResponse<CategoryValue>> {
|
|
try {
|
|
const response = await apiClient.put(`/category-tree/test/value/${valueId}`, input);
|
|
return response.data;
|
|
} catch (error: unknown) {
|
|
const err = error as { response?: { data?: { error?: string } }; message?: string };
|
|
return {
|
|
success: false,
|
|
error: err.response?.data?.error || err.message || "카테고리 값 수정 실패",
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 카테고리 값 삭제
|
|
*/
|
|
export async function deleteCategoryValue(valueId: number): Promise<ApiResponse<void>> {
|
|
try {
|
|
const response = await apiClient.delete(`/category-tree/test/value/${valueId}`);
|
|
return response.data;
|
|
} catch (error: unknown) {
|
|
const err = error as { response?: { data?: { error?: string } }; message?: string };
|
|
return {
|
|
success: false,
|
|
error: err.response?.data?.error || err.message || "카테고리 값 삭제 실패",
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 테이블의 카테고리 컬럼 목록 조회
|
|
*/
|
|
export async function getCategoryColumns(
|
|
tableName: string
|
|
): Promise<ApiResponse<{ columnName: string; columnLabel: string }[]>> {
|
|
try {
|
|
const response = await apiClient.get(`/category-tree/test/columns/${tableName}`);
|
|
return response.data;
|
|
} catch (error: unknown) {
|
|
const err = error as { response?: { data?: { error?: string } }; message?: string };
|
|
return {
|
|
success: false,
|
|
error: err.response?.data?.error || err.message || "카테고리 컬럼 조회 실패",
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 전체 카테고리 키 목록 조회 (모든 테이블.컬럼 조합)
|
|
*/
|
|
export async function getAllCategoryKeys(): Promise<ApiResponse<{ tableName: string; columnName: string }[]>> {
|
|
try {
|
|
const response = await apiClient.get("/category-tree/test/all-category-keys");
|
|
return response.data;
|
|
} catch (error: unknown) {
|
|
const err = error as { response?: { data?: { error?: string } }; message?: string };
|
|
return {
|
|
success: false,
|
|
error: err.response?.data?.error || err.message || "전체 카테고리 키 조회 실패",
|
|
};
|
|
}
|
|
}
|
|
|