Files
distribution_erp/src/app/api/admin/dept/delete/route.ts
T
chpark bd20680ba2
Deploy momo-erp / deploy (push) Successful in 48s
fix: FITO API 복원 + 사용자/부서/메뉴 삭제 정상화
- src/app/api/* (FITO 백엔드 API 약 70개) 복원 — (main) 페이지들이
  /api/product/bom, /api/sales/* 등을 호출하므로 복원 필요
- /api/admin/menus/delete: rel_menu_auth 컬럼명 오타 수정 (menu_obj_id → menu_objid)
- /api/admin/menus/delete: cascade 옵션 — 하위 메뉴까지 재귀 일괄 삭제
- /api/admin/users/delete 신규 (soft delete: status=inActive)
- /api/admin/dept/delete 신규 (자식 부서/소속 사용자 검사 후 soft delete)
- admin-panel 사용자 관리: handleDelete 빈 껍데기였음 → 실제 API 호출 + 체크박스 선택 연결
- admin-panel 부서 관리 모달: 삭제 버튼 추가
2026-04-26 00:16:30 +09:00

36 lines
1.7 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { execute, queryOne } from "@/lib/db";
import { getSession } from "@/lib/session";
export async function POST(req: NextRequest) {
const user = await getSession();
if (!user) return NextResponse.json({ success: false }, { status: 401 });
const { deptCode, deptCodes } = await req.json() as { deptCode?: string; deptCodes?: string[] };
const targets = deptCodes && deptCodes.length > 0 ? deptCodes : (deptCode ? [deptCode] : []);
if (targets.length === 0) {
return NextResponse.json({ success: false, message: "삭제할 부서를 선택하세요." }, { status: 400 });
}
// 자식 부서 검사
const placeholders = targets.map((_, i) => `$${i + 1}`).join(",");
const child = await queryOne<{ cnt: string }>(
`SELECT COUNT(*) AS cnt FROM dept_info WHERE parent_dept_code IN (${placeholders}) AND COALESCE(status,'active') != 'inActive'`,
targets
);
if (Number(child?.cnt || 0) > 0) {
return NextResponse.json({ success: false, message: `하위 부서 ${child!.cnt}개가 있어 삭제할 수 없습니다.` }, { status: 400 });
}
// 사용자 검사
const userCnt = await queryOne<{ cnt: string }>(
`SELECT COUNT(*) AS cnt FROM user_info WHERE dept_code IN (${placeholders}) AND COALESCE(status,'active') != 'inActive'`,
targets
);
if (Number(userCnt?.cnt || 0) > 0) {
return NextResponse.json({ success: false, message: `소속 사용자 ${userCnt!.cnt}명이 있어 삭제할 수 없습니다.` }, { status: 400 });
}
await execute(`UPDATE dept_info SET status='inActive' WHERE dept_code IN (${placeholders})`, targets);
return NextResponse.json({ success: true, count: targets.length });
}