fix: 用工办理必填项校验(前后端)+ 20260811优化验证文档

This commit is contained in:
selfrelease
2026-08-11 17:15:51 +08:00
parent de7f1830a7
commit b682178549
3 changed files with 439 additions and 29 deletions
+36
View File
@@ -7,6 +7,34 @@ import { createWorkProcessSchema, updateWorkProcessSchema } from '../schemas/wor
const router = Router()
// 各流程类型的必填字段映射
const REQUIRED_FIELDS: Record<string, string[]> = {
HIRE: ['name', 'department', 'hireDate', 'phone', 'idCardNumber'],
ONBOARD: ['employeeId', 'hireDate'],
CUSTOM_CONTRACT: ['employeeId', 'contractStartDate'],
INFO_SUBMIT: ['employeeId'],
CONFIRM: ['employeeId', 'confirmDate'],
CHANGE: ['contractId', 'newEndDate'],
RENEW: ['employeeId', 'newStartDate'],
SUSPEND: ['contractId', 'suspendDate'],
INCOME_CERT: ['employeeName', 'idCardNumber'],
TERMINATE: ['employeeId', 'terminateDate', 'reason'],
RESCIND: ['employeeId', 'rescindDate', 'reason'],
LEAVING_CERT: ['employeeName', 'idCardNumber', 'leaveDate'],
FLEXIBLE: ['name', 'idCardNumber', 'agreementStartDate'],
}
// 必填字段中文标签映射
const FIELD_LABELS: Record<string, string> = {
name: '员工姓名', department: '部门', hireDate: '入职日期', phone: '手机号',
idCardNumber: '身份证号', employeeId: '员工ID', contractId: '合同ID',
contractStartDate: '合同开始日期', confirmDate: '转正日期',
newEndDate: '新到期日期', newStartDate: '新合同开始日期',
suspendDate: '中止日期', employeeName: '员工姓名',
terminateDate: '终止日期', rescindDate: '解除日期', reason: '原因',
leaveDate: '离职日期', agreementStartDate: '协议开始日期',
}
// 创建办理(含草稿)
router.post('/', authMiddleware, async (req: AuthRequest, res: Response, next: NextFunction) => {
try {
@@ -108,6 +136,14 @@ router.post('/:id/submit', authMiddleware, async (req: AuthRequest, res: Respons
if (process.status !== 'DRAFT') {
return res.status(400).json({ success: false, error: { code: 'NOT_DRAFT', message: '仅草稿状态可提交' } })
}
// 后端必填字段校验
const required = REQUIRED_FIELDS[process.type] || []
const fd = process.formData || {}
const missing = required.filter((key) => !fd[key] || String(fd[key]).trim() === '')
if (missing.length > 0) {
const labels = missing.map((k) => FIELD_LABELS[k] || k).join('、')
return res.status(400).json({ success: false, error: { code: 'MISSING_REQUIRED', message: `请填写必填项:${labels}` } })
}
// 执行业务联动
let execResult: any = {}
try {