LP6 完善请假采购体验与审批说明
这个提交包含在:
@@ -94,6 +94,46 @@ const LEAVE_TYPE_SELECT = {
|
||||
},
|
||||
};
|
||||
|
||||
const LEAVE_WORKFLOW_SELECT = {
|
||||
orderBy: { created_at: "desc" },
|
||||
take: 1,
|
||||
select: {
|
||||
id: true,
|
||||
current_status: true,
|
||||
current_step_id: true,
|
||||
workflow_tasks: {
|
||||
where: { status: "pending" },
|
||||
orderBy: { created_at: "asc" },
|
||||
take: 1,
|
||||
select: {
|
||||
id: true,
|
||||
step_id: true,
|
||||
step_name: true,
|
||||
assignee_id: true,
|
||||
assignee_role: true,
|
||||
},
|
||||
},
|
||||
workflow_history: {
|
||||
orderBy: { created_at: "desc" },
|
||||
take: 8,
|
||||
select: {
|
||||
id: true,
|
||||
task_id: true,
|
||||
actor_id: true,
|
||||
action: true,
|
||||
comment: true,
|
||||
created_at: true,
|
||||
actor: {
|
||||
select: {
|
||||
employee_no: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
function buildValidationError(details, statusCode = 400) {
|
||||
return new AppError({
|
||||
code: "VALID_001",
|
||||
@@ -347,7 +387,43 @@ function mapLeaveTypeSummary(leaveType) {
|
||||
};
|
||||
}
|
||||
|
||||
function mapWorkflowHistoryItem(item) {
|
||||
return {
|
||||
id: item.id,
|
||||
taskId: item.task_id ?? null,
|
||||
actorId: item.actor_id,
|
||||
actorName: item.actor?.name ?? null,
|
||||
actorEmployeeNo: item.actor?.employee_no ?? null,
|
||||
action: item.action,
|
||||
comment: item.comment ?? null,
|
||||
createdAt: item.created_at?.toISOString?.() ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
function mapPendingWorkflow(instance) {
|
||||
if (!instance || instance.current_status !== "pending") {
|
||||
return null;
|
||||
}
|
||||
|
||||
const task = instance.workflow_tasks?.[0] ?? null;
|
||||
return {
|
||||
instanceId: instance.id,
|
||||
currentStatus: instance.current_status,
|
||||
currentStepId: instance.current_step_id,
|
||||
task: task
|
||||
? {
|
||||
id: task.id,
|
||||
stepId: task.step_id,
|
||||
stepName: task.step_name,
|
||||
assigneeId: task.assignee_id,
|
||||
assigneeRole: task.assignee_role,
|
||||
}
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
function mapLeaveRequestResponse(leave) {
|
||||
const latestWorkflow = leave.workflow_instances?.[0] ?? null;
|
||||
return {
|
||||
id: leave.id,
|
||||
ownerId: leave.owner_id,
|
||||
@@ -374,6 +450,8 @@ function mapLeaveRequestResponse(leave) {
|
||||
name: leave.owner.name,
|
||||
}
|
||||
: null,
|
||||
pendingWorkflow: mapPendingWorkflow(latestWorkflow),
|
||||
approvalHistory: (latestWorkflow?.workflow_history ?? []).map(mapWorkflowHistoryItem),
|
||||
createdAt: leave.created_at?.toISOString?.() ?? null,
|
||||
updatedAt: leave.updated_at?.toISOString?.() ?? null,
|
||||
};
|
||||
@@ -562,6 +640,7 @@ async function leaveRoutes(fastify) {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
workflow_instances: LEAVE_WORKFLOW_SELECT,
|
||||
},
|
||||
}),
|
||||
fastify.prisma.leaveRequest.count({ where }),
|
||||
@@ -668,6 +747,7 @@ async function leaveRoutes(fastify) {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
workflow_instances: LEAVE_WORKFLOW_SELECT,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -849,6 +929,7 @@ async function leaveRoutes(fastify) {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
workflow_instances: LEAVE_WORKFLOW_SELECT,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户