summaryrefslogtreecommitdiff
path: root/lib/knox-api/employee/code-utils.ts
blob: 36a0e2835b4c077376e16c82a028fd785f7dcbfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Knox 임직원/조직 코드 → 한글 설명 매핑
// 가이드의 Note 컬럼을 하드코딩해두었다.

const CODE_MAPS = {
  accountStatus: {
    A: '아이디 승인',
    W: '아이디 신청',
    M: '아이디 미발급',
  },
  defaultCompanyCode: {
    O: '원소속',
    S: '파견소속',
  },
  employeeStatus: {
    B: '재직',
    V: '휴직',
  },
  employeeType: {
    N: '정규직 (@samsung.com)',
    U: '협력직',
    C: '자회사',
    T: '임시직 (@partner.samsung.com)',
    X: '협력직 (@samsung.com)',
    Y: '자회사 (@samsung.com)',
    Z: '임시직 (@samsung.com)',
  },
  gradeTitleIndiCode: {
    G: '직위',
    T: '직급',
    B: '직위/직급 모두',
  },
  securityLevel: {
    '1': '회장단',
    '2': '사장단',
    '3': '임원진',
    '4': '간부',
    '5': '사원',
    '9': '협력사 임직원',
  },
  executiveYn: {
    Y: '임원',
    N: '직원',
  },
  realNameYn: {
    R: '실명',
    V: '가명',
  },
  localStaffYn: {
    Y: '현채인',
    N: '현채인 아님',
  },
  serverLocation: {
    KR: '한국',
    GB: '구주',
    US: '미주',
  },
} as const;

type CodeField = keyof typeof CODE_MAPS;
type CodeValue<F extends CodeField> = keyof (typeof CODE_MAPS)[F];

/**
 * 개별 코드 설명 반환
 * @param field 코드 필드명 (예: 'accountStatus')
 * @param code  코드 값 (예: 'A')
 * @returns    한글 설명 (없으면 undefined)
 */
export function getCodeDescription<F extends CodeField>(
  field: F,
  code: CodeValue<F> | string | undefined | null,
): string | undefined {
  if (!code) return undefined;
  // 대소문자 구분 없음 처리
  const normalized = String(code).toUpperCase() as CodeValue<F>;
  const map = CODE_MAPS[field] as Record<string, string>;
  return map[normalized as string];
}

/**
 * Employee 객체에 *_Desc 필드로 설명을 붙여 반환
 * (원본 객체는 수정하지 않음)
 */
export function withCodeDescriptions<T extends Record<string, unknown>>(employee: T) {
  const result: Record<string, unknown> = { ...employee };
  (Object.keys(CODE_MAPS) as CodeField[]).forEach((field) => {
    if (field in employee) {
      const desc = getCodeDescription(field, employee[field] as string);
      if (desc) result[`${field}Desc`] = desc;
    }
  });
  return result as T & { [K in `${CodeField}Desc`]?: string };
}

// export 전체 매핑이 필요하면 아래 내보내기
export { CODE_MAPS };