fix(WEB): 오늘의 이슈 badge 매핑 백엔드 동기화 및 fallback 추가

transformers.ts:
- NOTIFICATION_TYPE_TO_BADGE 백엔드 TodayIssue.php와 동기화
- BADGE_TO_NOTIFICATION_TYPE 역방향 매핑 추가 (fallback용)
- validateNotificationType에 badge 기반 추론 로직 추가

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
유병철
2026-01-28 15:58:27 +09:00
parent eb3288dab7
commit 381413a49c
3 changed files with 50 additions and 17 deletions

View File

@@ -81,11 +81,12 @@ const FILTER_KEYS = [
] as const;
// notification_type → 한글 라벨 매핑 (필터 표시용)
// 백엔드 TodayIssue.php BADGE 상수와 동기화!
const NOTIFICATION_TYPE_LABELS: Record<TodayIssueNotificationType, string> = {
sales_order: '수주 성공',
bad_debt: '추심 이슈',
safety_stock: '적정 재고',
expected_expense: '지출예상내역서',
sales_order: '수주등록',
bad_debt: '추심이슈',
safety_stock: '안전재고',
expected_expense: '지출 승인대기',
vat_report: '세금 신고',
approval_request: '결재 요청',
new_vendor: '신규거래처',

View File

@@ -69,12 +69,13 @@ export type TodayIssueNotificationType =
| 'withdrawal' // 출금
| 'other'; // 기타
// 오늘의 이슈 뱃지 타입 (한글 표시용 - deprecated, notificationType 사용 권장)
// 오늘의 이슈 뱃지 타입 (한글 표시용)
// 백엔드 TodayIssue.php BADGE 상수와 동기화!
export type TodayIssueListBadgeType =
| '수주 성공'
| '추심 이슈'
| '적정 재고'
| '지출예상내역서'
| '수주등록'
| '추심이슈'
| '안전재고'
| '지출 승인대기'
| '세금 신고'
| '결재 요청'
| '신규거래처'

View File

@@ -617,12 +617,14 @@ const VALID_NOTIFICATION_TYPES: TodayIssueNotificationType[] = [
'other',
];
/** notification_type → 한글 badge 변환 매핑 */
/** notification_type → 한글 badge 변환 매핑
* 백엔드 TodayIssue.php BADGE 상수와 동기화!
*/
const NOTIFICATION_TYPE_TO_BADGE: Record<TodayIssueNotificationType, TodayIssueListBadgeType> = {
sales_order: '수주 성공',
bad_debt: '추심 이슈',
safety_stock: '적정 재고',
expected_expense: '지출예상내역서',
sales_order: '수주등록',
bad_debt: '추심이슈',
safety_stock: '안전재고',
expected_expense: '지출 승인대기',
vat_report: '세금 신고',
approval_request: '결재 요청',
new_vendor: '신규거래처',
@@ -631,14 +633,42 @@ const NOTIFICATION_TYPE_TO_BADGE: Record<TodayIssueNotificationType, TodayIssueL
other: '기타',
};
/** 한글 badge → notification_type 추론 매핑 (fallback용)
* 백엔드 TodayIssue.php BADGE 상수와 동기화 필수!
*/
const BADGE_TO_NOTIFICATION_TYPE: Record<string, TodayIssueNotificationType> = {
// === 백엔드 실제 값 (TodayIssue.php 상수) ===
'수주등록': 'sales_order',
'추심이슈': 'bad_debt',
'안전재고': 'safety_stock',
'지출 승인대기': 'expected_expense',
'세금 신고': 'vat_report',
'결재 요청': 'approval_request',
'신규거래처': 'new_vendor',
'입금': 'deposit',
'출금': 'withdrawal',
// === 혹시 모를 변형 (안전장치) ===
'수주 등록': 'sales_order',
'추심 이슈': 'bad_debt',
'안전 재고': 'safety_stock',
'지출승인대기': 'expected_expense',
'세금신고': 'vat_report',
'결재요청': 'approval_request',
};
/**
* API notification_type → Frontend notificationType 변환
* 유효하지 않은 타입은 'other'로 폴백
* notification_type이 없으면 badge에서 추론
*/
function validateNotificationType(notificationType: string | null): TodayIssueNotificationType {
function validateNotificationType(notificationType: string | null, badge?: string): TodayIssueNotificationType {
// 1. notification_type이 유효하면 그대로 사용
if (notificationType && VALID_NOTIFICATION_TYPES.includes(notificationType as TodayIssueNotificationType)) {
return notificationType as TodayIssueNotificationType;
}
// 2. notification_type이 없으면 badge에서 추론
if (badge && BADGE_TO_NOTIFICATION_TYPE[badge]) {
return BADGE_TO_NOTIFICATION_TYPE[badge];
}
return 'other';
}
@@ -653,7 +683,8 @@ export function transformTodayIssueResponse(api: TodayIssueApiResponse): {
} {
return {
items: api.items.map((item) => {
const notificationType = validateNotificationType(item.notification_type);
// notification_type이 없으면 badge에서 추론
const notificationType = validateNotificationType(item.notification_type, item.badge);
// badge는 API 응답 그대로 사용하되, 없으면 notification_type에서 변환
const badge = item.badge || NOTIFICATION_TYPE_TO_BADGE[notificationType];