fix: 订单与档案接口收敛错误细节与写入校验

internalError 只把通用文案回给前端、详情进日志;状态迁移规则抽到 utils/record_state.js 单点维护;档案更新开 runValidators 并补姓名/手机号/身高体重校验与每人档案上限;已支付订单改为软删除保留审计。
This commit is contained in:
lik
2026-10-24 22:24:39 +08:00
committed by trae-solo-agent
parent 1774239553
commit f4760a4c5b
6 changed files with 174 additions and 32 deletions
+7 -4
View File
@@ -39,8 +39,9 @@ const HealthProfileSchema = mongoose.Schema(
// 健康信息
health: {
height: { type: Number, default: 0, comment: "身高(cm)" },
weight: { type: Number, default: 0, comment: "体重(kg)" },
// 范围校验:0 表示未填写;非法值(负数、超大值)以前会被静默写入并影响下单展示
height: { type: Number, min: 0, max: 300, default: 0, comment: "身高(cm)" },
weight: { type: Number, min: 0, max: 500, default: 0, comment: "体重(kg)" },
bloodType: { type: String, default: "", comment: "血型" },
remark: { type: String, default: "", comment: "备注" },
},
@@ -165,11 +166,13 @@ HealthProfileSchema.statics.createProfile = async function (data) {
/**
* 根据ID更新健康档案(更新姓名时同步拼音字段)
* runValidators: 更新时同样校验 schema 约束(性别枚举、身高体重范围),
* 否则非法值会绕过校验被静默写入
*/
HealthProfileSchema.statics.updateProfileById = async function (id, update) {
syncPinyinOnUpdate(update);
update["meta.updatetime"] = Date.now();
return await this.findByIdAndUpdate(id, { $set: update }, { new: true }).exec();
return await this.findByIdAndUpdate(id, { $set: update }, { new: true, runValidators: true }).exec();
};
/**
@@ -178,7 +181,7 @@ HealthProfileSchema.statics.updateProfileById = async function (id, update) {
HealthProfileSchema.statics.updateProfile = async function (userId, update) {
syncPinyinOnUpdate(update);
update["meta.updatetime"] = Date.now();
return await this.findOneAndUpdate({ userId }, { $set: update }, { new: true }).exec();
return await this.findOneAndUpdate({ userId }, { $set: update }, { new: true, runValidators: true }).exec();
};
/**