49 lines
2.4 KiB
TypeScript
49 lines
2.4 KiB
TypeScript
import type { RowMap } from '../app/itmsApi'
|
|
|
|
/*
|
|
* ITMS 리소스서버의 resultList 행은 느슨한 Map(정확한 컬럼명이 기관/모듈별로 상이)이다.
|
|
* 화면이 스키마에 강결합되지 않도록, 자주 쓰는 필드는 후보 키 목록에서 최초 존재값을 선택한다.
|
|
* (데이터 조작·목업 아님 — 실제 응답 필드를 방어적으로 표시.)
|
|
*/
|
|
export function pick(row: RowMap | null | undefined, keys: string[]): string {
|
|
if (!row) return ''
|
|
for (const k of keys) {
|
|
const v = row[k]
|
|
if (v !== undefined && v !== null && String(v).trim() !== '') return String(v)
|
|
}
|
|
return ''
|
|
}
|
|
|
|
const TITLE_KEYS = ['title', 'incidentTitle', 'reqTitle', 'nttSj', 'ntt_sj', 'sj', 'subject', 'svcNm', 'serviceNm', 'resrceNm', 'assetNm', 'name', 'contents', 'incidentCn']
|
|
const STATUS_KEYS = ['statusNm', 'sttusNm', 'sttusName', 'procSttusNm', 'progrsSttusNm', 'incidentSttusNm', 'sttus', 'status', 'procSttus', 'progrsSttus', 'state']
|
|
const DATE_KEYS = ['regDt', 'regDate', 'reqDt', 'reqDate', 'frstRegisterPnttm', 'createDt', 'createdAt', 'ntcrDt', 'registDt', 'occrDt']
|
|
const AUTHOR_KEYS = ['reqUserNm', 'reqrNm', 'registerNm', 'writerNm', 'ntcrNm', 'userName', 'userNm', 'chargerNm']
|
|
|
|
export const rowTitle = (row: RowMap) => pick(row, TITLE_KEYS) || '(제목 없음)'
|
|
export const rowStatus = (row: RowMap) => pick(row, STATUS_KEYS)
|
|
export const rowDate = (row: RowMap) => {
|
|
const d = pick(row, DATE_KEYS)
|
|
return d ? d.slice(0, 16) : ''
|
|
}
|
|
export const rowAuthor = (row: RowMap) => pick(row, AUTHOR_KEYS)
|
|
|
|
/** SR 요청 식별자(상세 조회용) 후보. */
|
|
export const reqIncidentNum = (row: RowMap) => pick(row, ['vcReqIncidentNum', 'reqIncidentNum', 'incidentReqNum', 'incidentNum'])
|
|
/** 인시던트 seq 후보. */
|
|
export const incidentSeq = (row: RowMap) => pick(row, ['inIncidentSeq', 'incidentSeq', 'seq', 'incidentId'])
|
|
|
|
/** row 를 라벨:값 나열용 항목으로 평탄화(내부 메타/빈값 제외). */
|
|
export function rowEntries(row: RowMap | null | undefined, limit = 40): { key: string; value: string }[] {
|
|
if (!row) return []
|
|
const out: { key: string; value: string }[] = []
|
|
for (const [k, v] of Object.entries(row)) {
|
|
if (v === null || v === undefined) continue
|
|
if (typeof v === 'object') continue
|
|
const s = String(v).trim()
|
|
if (!s) continue
|
|
out.push({ key: k, value: s })
|
|
if (out.length >= limit) break
|
|
}
|
|
return out
|
|
}
|