테이블 컬럼추가 오류 수정
This commit is contained in:
@@ -36,29 +36,61 @@ export async function getSiblingMenuObjids(menuObjid: number): Promise<number[]>
|
||||
try {
|
||||
logger.debug("메뉴 스코프 조회 시작", { menuObjid });
|
||||
|
||||
// 1. 현재 메뉴 자신을 포함
|
||||
const menuObjids = [menuObjid];
|
||||
// 1. 현재 메뉴 정보 조회 (부모 ID 확인)
|
||||
const currentMenuQuery = `
|
||||
SELECT parent_obj_id FROM menu_info
|
||||
WHERE objid = $1
|
||||
`;
|
||||
const currentMenuResult = await pool.query(currentMenuQuery, [menuObjid]);
|
||||
|
||||
// 2. 현재 메뉴의 자식 메뉴들 조회
|
||||
const childrenQuery = `
|
||||
if (currentMenuResult.rows.length === 0) {
|
||||
logger.warn("메뉴를 찾을 수 없음, 자기 자신만 반환", { menuObjid });
|
||||
return [menuObjid];
|
||||
}
|
||||
|
||||
const parentObjId = Number(currentMenuResult.rows[0].parent_obj_id);
|
||||
|
||||
// 2. 최상위 메뉴(parent_obj_id = 0)는 자기 자신만 반환
|
||||
if (parentObjId === 0) {
|
||||
logger.debug("최상위 메뉴, 자기 자신만 반환", { menuObjid });
|
||||
return [menuObjid];
|
||||
}
|
||||
|
||||
// 3. 형제 메뉴들 조회 (같은 부모를 가진 메뉴들)
|
||||
const siblingsQuery = `
|
||||
SELECT objid FROM menu_info
|
||||
WHERE parent_obj_id = $1
|
||||
ORDER BY objid
|
||||
`;
|
||||
const childrenResult = await pool.query(childrenQuery, [menuObjid]);
|
||||
const siblingsResult = await pool.query(siblingsQuery, [parentObjId]);
|
||||
|
||||
const childObjids = childrenResult.rows.map((row) => Number(row.objid));
|
||||
const siblingObjids = siblingsResult.rows.map((row) => Number(row.objid));
|
||||
|
||||
// 3. 자신 + 자식을 합쳐서 정렬
|
||||
const allObjids = Array.from(new Set([...menuObjids, ...childObjids])).sort((a, b) => a - b);
|
||||
// 4. 각 형제 메뉴(자기 자신 포함)의 자식 메뉴들도 조회
|
||||
const allObjids = [...siblingObjids];
|
||||
|
||||
for (const siblingObjid of siblingObjids) {
|
||||
const childrenQuery = `
|
||||
SELECT objid FROM menu_info
|
||||
WHERE parent_obj_id = $1
|
||||
ORDER BY objid
|
||||
`;
|
||||
const childrenResult = await pool.query(childrenQuery, [siblingObjid]);
|
||||
const childObjids = childrenResult.rows.map((row) => Number(row.objid));
|
||||
allObjids.push(...childObjids);
|
||||
}
|
||||
|
||||
// 5. 중복 제거 및 정렬
|
||||
const uniqueObjids = Array.from(new Set(allObjids)).sort((a, b) => a - b);
|
||||
|
||||
logger.debug("메뉴 스코프 조회 완료", {
|
||||
menuObjid,
|
||||
childCount: childObjids.length,
|
||||
totalCount: allObjids.length
|
||||
menuObjid,
|
||||
parentObjId,
|
||||
siblingCount: siblingObjids.length,
|
||||
totalCount: uniqueObjids.length
|
||||
});
|
||||
|
||||
return allObjids;
|
||||
return uniqueObjids;
|
||||
} catch (error: any) {
|
||||
logger.error("메뉴 스코프 조회 실패", {
|
||||
menuObjid,
|
||||
|
||||
Reference in New Issue
Block a user