blob: d74c7d1e687e4fae2e72a675cef9c984b6d32bde (
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
|
export interface SimpleApln {
seq: string
name?: string
emailAddress?: string
role: string
}
export function formatApprovalLine(aplns: SimpleApln[]): string {
if (!aplns || aplns.length === 0) return '결재자 없음'
const roleMap: Record<string, string> = {
'0': '기안',
'1': '결재',
'2': '합의',
'3': '후결',
'4': '병렬합의',
'7': '병렬결재',
'9': '통보',
}
const groupedBySeq = aplns.reduce<Record<string, SimpleApln[]>>((groups, apln) => {
const seq = apln.seq
if (!groups[seq]) groups[seq] = []
groups[seq].push(apln)
return groups
}, {})
const sortedSeqs = Object.keys(groupedBySeq).sort((a, b) => parseInt(a) - parseInt(b))
return sortedSeqs
.map((seq) => {
const group = groupedBySeq[seq]
const isParallel = group.length > 1 || group.some((apln) => apln.role === '4' || apln.role === '7')
if (isParallel) {
const parallelMembers = group
.map((apln) => {
const name = apln.name || apln.emailAddress || '이름없음'
const role = roleMap[apln.role] || '알수없음'
return `${name}(${role})`
})
.join(', ')
return `[${parallelMembers}]`
} else {
const apln = group[0]
const name = apln.name || apln.emailAddress || '이름없음'
const role = roleMap[apln.role] || '알수없음'
return `${name}(${role})`
}
})
.join(' → ')
}
|