diff options
Diffstat (limited to 'lib/approval-line/utils')
| -rw-r--r-- | lib/approval-line/utils/format.ts | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/approval-line/utils/format.ts b/lib/approval-line/utils/format.ts new file mode 100644 index 00000000..d74c7d1e --- /dev/null +++ b/lib/approval-line/utils/format.ts @@ -0,0 +1,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(' → ') +} + + |
