fix: 订单与档案接口收敛错误细节与写入校验
internalError 只把通用文案回给前端、详情进日志;状态迁移规则抽到 utils/record_state.js 单点维护;档案更新开 runValidators 并补姓名/手机号/身高体重校验与每人档案上限;已支付订单改为软删除保留审计。
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* 陪诊订单状态机(HTTP 接口与管理端 Agent 工具共用同一份规则)
|
||||
*
|
||||
* 之前 Agent 的 escort_record_set 直接改 status,绕过了接口层的迁移校验,
|
||||
* 可以把已完成订单改回进行中。规则集中在这里,任何入口都必须走 canTransition。
|
||||
*/
|
||||
|
||||
// 允许的状态迁移;终态不可再变
|
||||
const STATUS_TRANSITIONS = {
|
||||
pending: ["confirmed", "cancelled"],
|
||||
confirmed: ["in_progress", "cancelled"],
|
||||
in_progress: ["completed"],
|
||||
completed: [],
|
||||
cancelled: [],
|
||||
};
|
||||
|
||||
/**
|
||||
* 判断状态迁移是否允许
|
||||
* @param {string} from 当前状态
|
||||
* @param {string} to 目标状态
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function canTransition(from, to) {
|
||||
return (STATUS_TRANSITIONS[from] || []).includes(to);
|
||||
}
|
||||
|
||||
export { STATUS_TRANSITIONS, canTransition };
|
||||
Reference in New Issue
Block a user