ai review

This commit is contained in:
lik
2026-09-01 21:49:17 +08:00
parent 390c871d35
commit 98c9026485
14 changed files with 288 additions and 262 deletions
+5 -8
View File
@@ -21,7 +21,7 @@ const HealthProfileSchema = mongoose.Schema(
name: { type: String, default: "", comment: "患者姓名" },
mobile: { type: String, default: "", index: true, comment: "患者电话" },
sex: { type: String, enum: ["male", "female", ""], default: "", comment: "性别" },
age: { type: Number, default: 0, comment: "年龄" },
birth: { type: String, default: "", comment: "出生年月(YYYY-MM-DD" },
idnumber: { type: String, default: "", comment: "身份证号" },
},
@@ -76,7 +76,9 @@ HealthProfileSchema.statics.findByUserId = async function (userId) {
filter.userId = userId;
}
if (name) {
filter["profile.name"] = { $regex: name, $options: "i" };
// 转义正则特殊字符,避免查询报错或 ReDoS
const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
filter["profile.name"] = { $regex: escaped, $options: "i" };
}
if (mobile) {
filter["profile.mobile"] = mobile;
@@ -132,12 +134,7 @@ HealthProfileSchema.statics.updateProfile = async function (userId, update) {
* 根据ID删除健康档案
*/
HealthProfileSchema.statics.deleteProfileById = async function (id) {
try {
return await this.findByIdAndDelete(id).exec();
} catch (error) {
console.error("删除健康档案失败:", error);
return null;
}
return await this.findByIdAndDelete(id).exec();
};
// ==================== 索引定义 ====================