카테고리 구현
This commit is contained in:
@@ -6,54 +6,6 @@ import {
|
||||
} from "../types/tableCategoryValue";
|
||||
|
||||
class TableCategoryValueService {
|
||||
/**
|
||||
* 메뉴의 형제 메뉴 ID 목록 조회
|
||||
* (같은 부모를 가진 메뉴들)
|
||||
*/
|
||||
async getSiblingMenuIds(menuId: number): Promise<number[]> {
|
||||
try {
|
||||
const pool = getPool();
|
||||
|
||||
// 1. 현재 메뉴의 부모 ID 조회 (menu_info는 objid와 parent_obj_id 사용)
|
||||
const parentQuery = `
|
||||
SELECT parent_obj_id FROM menu_info WHERE objid = $1
|
||||
`;
|
||||
const parentResult = await pool.query(parentQuery, [menuId]);
|
||||
|
||||
if (parentResult.rows.length === 0) {
|
||||
logger.warn(`메뉴 ID ${menuId}를 찾을 수 없습니다`);
|
||||
return [menuId];
|
||||
}
|
||||
|
||||
const parentId = parentResult.rows[0].parent_obj_id;
|
||||
|
||||
// 최상위 메뉴인 경우 (parent_obj_id가 null 또는 0)
|
||||
if (!parentId || parentId === 0) {
|
||||
logger.info(`메뉴 ${menuId}는 최상위 메뉴입니다`);
|
||||
return [menuId];
|
||||
}
|
||||
|
||||
// 2. 같은 부모를 가진 형제 메뉴들 조회
|
||||
const siblingsQuery = `
|
||||
SELECT objid FROM menu_info WHERE parent_obj_id = $1
|
||||
`;
|
||||
const siblingsResult = await pool.query(siblingsQuery, [parentId]);
|
||||
|
||||
const siblingIds = siblingsResult.rows.map((row) => Number(row.objid));
|
||||
|
||||
logger.info(`메뉴 ${menuId}의 형제 메뉴 ${siblingIds.length}개 조회`, {
|
||||
menuId,
|
||||
parentId,
|
||||
siblings: siblingIds,
|
||||
});
|
||||
|
||||
return siblingIds;
|
||||
} catch (error: any) {
|
||||
logger.error(`형제 메뉴 조회 실패: ${error.message}`);
|
||||
// 에러 시 현재 메뉴만 반환
|
||||
return [menuId];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 테이블의 카테고리 타입 컬럼 목록 조회
|
||||
*/
|
||||
@@ -98,12 +50,11 @@ class TableCategoryValueService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 컬럼의 카테고리 값 목록 조회 (메뉴 스코프 적용)
|
||||
* 특정 컬럼의 카테고리 값 목록 조회 (테이블 스코프)
|
||||
*/
|
||||
async getCategoryValues(
|
||||
tableName: string,
|
||||
columnName: string,
|
||||
menuId: number,
|
||||
companyCode: string,
|
||||
includeInactive: boolean = false
|
||||
): Promise<TableCategoryValue[]> {
|
||||
@@ -111,14 +62,10 @@ class TableCategoryValueService {
|
||||
logger.info("카테고리 값 목록 조회", {
|
||||
tableName,
|
||||
columnName,
|
||||
menuId,
|
||||
companyCode,
|
||||
includeInactive,
|
||||
});
|
||||
|
||||
// 1. 메뉴 스코프 확인: 형제 메뉴들의 카테고리도 포함
|
||||
const siblingMenuIds = await this.getSiblingMenuIds(menuId);
|
||||
|
||||
const pool = getPool();
|
||||
let query = `
|
||||
SELECT
|
||||
@@ -135,7 +82,6 @@ class TableCategoryValueService {
|
||||
icon,
|
||||
is_active AS "isActive",
|
||||
is_default AS "isDefault",
|
||||
menu_objid AS "menuId",
|
||||
company_code AS "companyCode",
|
||||
created_at AS "createdAt",
|
||||
updated_at AS "updatedAt",
|
||||
@@ -144,16 +90,10 @@ class TableCategoryValueService {
|
||||
FROM table_column_category_values
|
||||
WHERE table_name = $1
|
||||
AND column_name = $2
|
||||
AND menu_objid = ANY($3)
|
||||
AND (company_code = $4 OR company_code = '*')
|
||||
AND (company_code = $3 OR company_code = '*')
|
||||
`;
|
||||
|
||||
const params: any[] = [
|
||||
tableName,
|
||||
columnName,
|
||||
siblingMenuIds,
|
||||
companyCode,
|
||||
];
|
||||
const params: any[] = [tableName, columnName, companyCode];
|
||||
|
||||
if (!includeInactive) {
|
||||
query += ` AND is_active = true`;
|
||||
@@ -169,8 +109,6 @@ class TableCategoryValueService {
|
||||
logger.info(`카테고리 값 ${result.rows.length}개 조회 완료`, {
|
||||
tableName,
|
||||
columnName,
|
||||
menuId,
|
||||
siblingMenuIds,
|
||||
});
|
||||
|
||||
return values;
|
||||
@@ -216,8 +154,8 @@ class TableCategoryValueService {
|
||||
INSERT INTO table_column_category_values (
|
||||
table_name, column_name, value_code, value_label, value_order,
|
||||
parent_value_id, depth, description, color, icon,
|
||||
is_active, is_default, menu_objid, company_code, created_by
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)
|
||||
is_active, is_default, company_code, created_by
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)
|
||||
RETURNING
|
||||
value_id AS "valueId",
|
||||
table_name AS "tableName",
|
||||
@@ -232,7 +170,6 @@ class TableCategoryValueService {
|
||||
icon,
|
||||
is_active AS "isActive",
|
||||
is_default AS "isDefault",
|
||||
menu_objid AS "menuId",
|
||||
company_code AS "companyCode",
|
||||
created_at AS "createdAt",
|
||||
created_by AS "createdBy"
|
||||
@@ -251,7 +188,6 @@ class TableCategoryValueService {
|
||||
value.icon || null,
|
||||
value.isActive !== false,
|
||||
value.isDefault || false,
|
||||
value.menuId, // menuId 추가
|
||||
companyCode,
|
||||
userId,
|
||||
]);
|
||||
@@ -343,7 +279,6 @@ class TableCategoryValueService {
|
||||
icon,
|
||||
is_active AS "isActive",
|
||||
is_default AS "isDefault",
|
||||
menu_objid AS "menuId",
|
||||
updated_at AS "updatedAt",
|
||||
updated_by AS "updatedBy"
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user