feat: Implement approval request validation and enhance UI components
- Added validation to prevent duplicate approval requests for the same target, ensuring that only one active or completed approval exists at a time. - Implemented a check to disallow self-approval in the approval line unless the approval type is 'self'. - Integrated the ApprovalDetailModal component into the main layout for improved user experience. - Updated the SalesOrderPage to include approval status in the data structure, enhancing visibility of approval states. - Enhanced BOM management modals across multiple company implementations to accommodate new UI requirements.
This commit is contained in:
@@ -892,6 +892,40 @@ export class ApprovalRequestController {
|
||||
const userName = req.user?.userName || "";
|
||||
const deptName = req.user?.deptName || "";
|
||||
|
||||
// 🔒 중복 결재 차단: 같은 target에 활성/완료된 결재가 있으면 거부
|
||||
// (rejected, cancelled는 재상신 허용)
|
||||
if (target_record_id) {
|
||||
const existing = await queryOne<any>(
|
||||
`SELECT request_id, status FROM approval_requests
|
||||
WHERE target_table = $1 AND target_record_id = $2 AND company_code = $3
|
||||
AND status IN ('requested', 'in_progress', 'approved', 'post_pending')
|
||||
ORDER BY request_id DESC LIMIT 1`,
|
||||
[target_table, safeTargetRecordId, companyCode]
|
||||
);
|
||||
if (existing) {
|
||||
const statusLabel: Record<string, string> = {
|
||||
requested: "요청됨", in_progress: "결재중", approved: "승인완료", post_pending: "후결대기",
|
||||
};
|
||||
return res.status(409).json({
|
||||
success: false,
|
||||
message: `이미 ${statusLabel[existing.status] || existing.status} 상태의 결재가 존재합니다. (요청 ID: ${existing.request_id})`,
|
||||
error: { code: "DUPLICATE_APPROVAL", details: existing },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 🔒 자기 자신 결재 차단: approval_type이 'self'가 아니면 결재선에 본인 포함 불가
|
||||
if (approval_type !== "self" && Array.isArray(approvers)) {
|
||||
const selfInLine = approvers.find((a: any) => (a.userId || a.user_id) === userId);
|
||||
if (selfInLine) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: "결재선에 본인을 포함할 수 없습니다. 자기결재(전결)는 별도 유형을 사용해 주세요.",
|
||||
error: { code: "SELF_APPROVER_NOT_ALLOWED" },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// approval_mode를 target_record_data에 병합 저장 (하위호환)
|
||||
const mergedRecordData = {
|
||||
...(target_record_data || {}),
|
||||
|
||||
Reference in New Issue
Block a user