59 lines
2.4 KiB
TypeScript
59 lines
2.4 KiB
TypeScript
import { listJobLabel } from '@/const/listJobConst'
|
|
import type { ListJob } from '@/types/list-job'
|
|
|
|
/** SID와 수신자 건수는 단위가 다르므로 합산하지 않는다. */
|
|
export function formatMessageJobResult(progress: ListJob['progress']): string {
|
|
const p = progress ?? {}
|
|
const accepted = p.acceptedRecipientCnt
|
|
const parts = [typeof accepted === 'number' && Number.isSafeInteger(accepted) && accepted >= 0
|
|
? `${accepted.toLocaleString()}건 접수 완료` : '접수 건수 확인 불가']
|
|
const fields = [
|
|
['preparationFailedSidCnt', '준비 실패 SID', '개'],
|
|
['noDestinationSkippedSidCnt', '수신처 없음 SID', '개 제외'],
|
|
['failedRecipientCnt', '접수 실패', '건'],
|
|
['unknownRecipientCnt', '접수 여부 불명', '건'],
|
|
] as const
|
|
for (const [field, label, unit] of fields) {
|
|
const value = p[field]
|
|
if (typeof value === 'number' && Number.isSafeInteger(value) && value > 0) {
|
|
parts.push(`${label} ${value.toLocaleString()}${unit}`)
|
|
}
|
|
}
|
|
return parts.join(', ')
|
|
}
|
|
|
|
type JobNotification = {
|
|
kind: 'success' | 'warning' | 'info' | 'error'
|
|
message: string
|
|
description?: string
|
|
}
|
|
|
|
/** errorCode가 있어도 최종 성공 여부는 서버 jobStatus를 따른다. */
|
|
export function getListJobResultNotification(job: ListJob): JobNotification {
|
|
const label = listJobLabel(job.jobType, job.operation)
|
|
const messageJob = job.jobType.endsWith('_BULK')
|
|
const summary = messageJob ? formatMessageJobResult(job.progress) : undefined
|
|
switch (job.jobStatus) {
|
|
case 'SUCCEEDED':
|
|
return {
|
|
kind: 'success',
|
|
message: messageJob ? `${label} 접수 완료` : `${label} 작업이 완료됐습니다.`,
|
|
description: summary,
|
|
}
|
|
case 'PARTIALLY_SUCCEEDED':
|
|
return {
|
|
kind: 'warning',
|
|
message: `${label} 일부 접수 완료`,
|
|
description: [summary, '접수는 실제 전달 완료가 아닙니다. 전체 재발송 전에 접수 내역을 확인해 주세요.'].filter(Boolean).join('\n'),
|
|
}
|
|
case 'CANCELLED':
|
|
return { kind: 'info', message: `${label} 작업이 중단됐습니다.`, description: summary }
|
|
default:
|
|
return {
|
|
kind: 'error',
|
|
message: job.jobStatus === 'REJECTED' ? `${label} 접수가 거절됐습니다.` : `${label} 작업이 실패했습니다.`,
|
|
description: [job.errorMessage, summary].filter(Boolean).join('\n'),
|
|
}
|
|
}
|
|
}
|