feat: enhance category value retrieval with company code filtering

- Updated the `getCategoryValues` function to allow filtering based on a specified company code when requested by a super admin.
- Modified the service layer to ensure that super admins can retrieve common category values while preventing data mixing from different companies.
- Adjusted the frontend component to include the filter parameter in API requests, ensuring that the correct company-specific categories are displayed.

Made-with: Cursor
This commit is contained in:
kjs
2026-03-11 17:53:41 +09:00
parent d890155354
commit 62a5ae5f4b
3 changed files with 35 additions and 24 deletions

View File

@@ -62,24 +62,31 @@ export const getAllCategoryColumns = async (req: AuthenticatedRequest, res: Resp
*/
export const getCategoryValues = async (req: AuthenticatedRequest, res: Response) => {
try {
const companyCode = req.user!.companyCode;
const userCompanyCode = req.user!.companyCode;
const { tableName, columnName } = req.params;
const includeInactive = req.query.includeInactive === "true";
const menuObjid = req.query.menuObjid ? Number(req.query.menuObjid) : undefined;
const filterCompanyCode = req.query.filterCompanyCode as string | undefined;
// 최고관리자가 특정 회사 기준 필터링을 요청한 경우 해당 회사 코드 사용
const effectiveCompanyCode = (userCompanyCode === "*" && filterCompanyCode)
? filterCompanyCode
: userCompanyCode;
logger.info("카테고리 값 조회 요청", {
tableName,
columnName,
menuObjid,
companyCode,
companyCode: effectiveCompanyCode,
filterCompanyCode,
});
const values = await tableCategoryValueService.getCategoryValues(
tableName,
columnName,
companyCode,
effectiveCompanyCode,
includeInactive,
menuObjid // ← menuObjid 전달
menuObjid
);
return res.json({

View File

@@ -217,12 +217,12 @@ class TableCategoryValueService {
AND column_name = $2
`;
// category_values 테이블 사용 (menu_objid 없음)
// company_code 기반 필터링
if (companyCode === "*") {
// 최고 관리자: 모든 값 조회
query = baseSelect;
// 최고 관리자: 공통(*) 카테고리만 조회 (모든 회사 카테고리 혼합 방지)
query = baseSelect + ` AND company_code = '*'`;
params = [tableName, columnName];
logger.info("최고 관리자 전체 카테고리 조회 (category_values)");
logger.info("최고 관리자: 공통 카테고리 조회 (category_values)");
} else {
// 일반 회사: 자신의 회사 또는 공통(*) 카테고리 조회
query = baseSelect + ` AND (company_code = $3 OR company_code = '*')`;