refactor: API口径统一 — 统计函数/员工列表/前端服务层
后端: - /dashboard/compliance-score 改用 getHealthCheck,与体检诊断同口径 - 新增 /employees/list 端点(不分页,供各页面下拉选择) - /employees/all-lite 增加 position 字段和 status 筛选参数 - getHealthCheck 未签合同改为查无合同记录的员工(非UNSIGNED类型) 前端: - 新建 lib/api-services.ts 统一 API 服务层 - employeeApi/rosterApi/dashboardApi/attendanceApi 统一封装 - 6个页面迁移到统一 API 调用: - Attendance: employeeApi.list + rosterApi.departments - Termination: rosterApi.list + rosterApi.departments - Money: rosterApi.list + rosterApi.departments - PortalQRModal: employeeApi.list - AIAssistant: 3处 employeeApi.list 替代 /roster?pageSize=999 - Contracts: rosterApi.departments - Dashboard: rosterApi.expiringContracts + dashboardApi.healthCheck/workforceStats
This commit is contained in:
@@ -99,10 +99,10 @@ router.get('/cost-analysis', authMiddleware, async (req: AuthRequest, res: Respo
|
||||
}
|
||||
})
|
||||
|
||||
// 合规健康度评分 + AI 建议卡片流
|
||||
// 合规健康度评分 — 已统一为 getHealthCheck 口径
|
||||
router.get('/compliance-score', authMiddleware, async (req: AuthRequest, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const data = await getComplianceScore(req.user!.orgId)
|
||||
const data = await getHealthCheck(req.user!.orgId)
|
||||
res.json({ success: true, data })
|
||||
} catch (err) {
|
||||
next(err)
|
||||
|
||||
@@ -37,14 +37,49 @@ router.get('/', authMiddleware, async (req: AuthRequest, res, next) => {
|
||||
})
|
||||
|
||||
/**
|
||||
* 轻量级全量员工列表(不分页,仅返回 id/name/department/gender/status)
|
||||
* 轻量级全量员工列表(不分页,仅返回 id/name/department/position/gender/status)
|
||||
* 用于特殊状态台账、发薪批次等需要选择全部员工的场景
|
||||
* 支持 status 筛选参数,默认返回 ACTIVE
|
||||
*/
|
||||
router.get('/all-lite', authMiddleware, async (req: AuthRequest, res, next) => {
|
||||
try {
|
||||
const status = req.query.status
|
||||
? String(req.query.status).split(',') as any[]
|
||||
: ['ACTIVE', 'RESIGNED'] as any[]
|
||||
const department = req.query.department as string | undefined
|
||||
const employees = await prisma.employee.findMany({
|
||||
where: { orgId: req.user!.orgId, status: { in: ['ACTIVE', 'RESIGNED'] } },
|
||||
select: { id: true, name: true, department: true, gender: true, status: true },
|
||||
where: {
|
||||
orgId: req.user!.orgId,
|
||||
status: { in: status },
|
||||
...(department && { department }),
|
||||
},
|
||||
select: { id: true, name: true, department: true, position: true, gender: true, status: true },
|
||||
orderBy: { name: 'asc' },
|
||||
})
|
||||
res.json({ success: true, data: employees })
|
||||
} catch (err) {
|
||||
next(err)
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* 标准员工列表(不分页,供各页面下拉选择、引用等场景)
|
||||
* 与 /roster 分离,/roster 专用于花名册分页列表
|
||||
* 支持 status、department 筛选
|
||||
*/
|
||||
router.get('/list', authMiddleware, async (req: AuthRequest, res, next) => {
|
||||
try {
|
||||
const status = req.query.status
|
||||
? String(req.query.status).split(',') as any[]
|
||||
: ['ACTIVE'] as any[]
|
||||
const department = req.query.department as string | undefined
|
||||
const employees = await prisma.employee.findMany({
|
||||
where: {
|
||||
orgId: req.user!.orgId,
|
||||
status: { in: status },
|
||||
...(department && { department }),
|
||||
},
|
||||
select: { id: true, name: true, department: true, position: true, phone: true, status: true },
|
||||
orderBy: { name: 'asc' },
|
||||
})
|
||||
res.json({ success: true, data: employees })
|
||||
|
||||
Reference in New Issue
Block a user