62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
import type { ElaprAplnRow } from "../model/apln-row-types";
|
|
|
|
export const ATRZ_REVIEWER_CD = "ATRZ01";
|
|
export const ATRZ_FINAL_CD = "ATRZ03";
|
|
|
|
/** 검토자 최상단 · 최종승인자 최하단 순서 검증 */
|
|
export function validateAtrzOrder(rows: ElaprAplnRow[]): string | null {
|
|
const reviewerIndices = rows
|
|
.map((row, index) => (row.atrzSeComCd === ATRZ_REVIEWER_CD ? index : -1))
|
|
.filter((index) => index >= 0);
|
|
|
|
if (reviewerIndices.length > 0) {
|
|
const lastReviewerIndex = Math.max(...reviewerIndices);
|
|
const hasNonReviewerAbove = rows
|
|
.slice(0, lastReviewerIndex)
|
|
.some((row) => row.atrzSeComCd && row.atrzSeComCd !== ATRZ_REVIEWER_CD);
|
|
|
|
if (hasNonReviewerAbove) {
|
|
return "검토자는 결재선 최상단에만 배치할 수 있습니다.";
|
|
}
|
|
}
|
|
|
|
const finalIndices = rows
|
|
.map((row, index) => (row.atrzSeComCd === ATRZ_FINAL_CD ? index : -1))
|
|
.filter((index) => index >= 0);
|
|
|
|
if (finalIndices.length > 0) {
|
|
const firstFinalIndex = Math.min(...finalIndices);
|
|
const hasNonFinalBelow = rows
|
|
.slice(firstFinalIndex + 1)
|
|
.some((row) => row.atrzSeComCd && row.atrzSeComCd !== ATRZ_FINAL_CD);
|
|
|
|
if (hasNonFinalBelow) {
|
|
return "최종승인자는 결재선 최하단에만 배치할 수 있습니다.";
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
export function validateAplnRow(row: ElaprAplnRow): string | null {
|
|
if (!row.atrzSeComCd?.trim()) {
|
|
return "결재구분을 선택해 주세요.";
|
|
}
|
|
if (!row.aprvrUuid?.trim()) {
|
|
return "결재자를 선택해 주세요.";
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function validateUniqueSeqNo(rows: ElaprAplnRow[]): string | null {
|
|
const seqSet = new Set<number>();
|
|
for (const row of rows) {
|
|
if (row.atrzSeqNo == null) continue;
|
|
if (seqSet.has(row.atrzSeqNo)) {
|
|
return "동일 서식 내 결재순서번호가 중복됩니다.";
|
|
}
|
|
seqSet.add(row.atrzSeqNo);
|
|
}
|
|
return null;
|
|
}
|