tmp
This commit is contained in:
@@ -22,7 +22,16 @@ const HealthProfileSchema = mongoose.Schema(
|
||||
mobile: { type: String, default: "", index: true, comment: "患者电话" },
|
||||
sex: { type: String, enum: ["male", "female", ""], default: "", comment: "性别" },
|
||||
birth: { type: String, default: "", comment: "出生年月(YYYY-MM-DD)" },
|
||||
idnumber: { type: String, default: "", comment: "身份证号" },
|
||||
idnumber: { type: String, default: "", comment: "证件号(身份证/护照等)" },
|
||||
},
|
||||
|
||||
// 所在地(国外用户填国家;国内用户填省市区 + 详细地址)
|
||||
location: {
|
||||
country: { type: String, default: "中国", comment: "国家" },
|
||||
province: { type: String, default: "", comment: "省" },
|
||||
city: { type: String, default: "", comment: "市" },
|
||||
district: { type: String, default: "", comment: "区/县" },
|
||||
address: { type: String, default: "", comment: "详细地址" },
|
||||
},
|
||||
|
||||
// 健康信息
|
||||
@@ -68,27 +77,27 @@ HealthProfileSchema.statics.findByUserId = async function (userId) {
|
||||
* @param {string} [options.sortBy="createtime"] - 排序字段:createtime | updatetime(可选)
|
||||
* @returns {Promise<Object>} 返回 `{ list, total, page, pageSize }`
|
||||
*/
|
||||
HealthProfileSchema.statics.findProfiles = async function (options = {}) {
|
||||
const { page = 1, pageSize = 20, userId, name, mobile, sortBy = "createtime" } = options;
|
||||
const filter = {};
|
||||
HealthProfileSchema.statics.findProfiles = async function (options = {}) {
|
||||
const { page = 1, pageSize = 20, userId, name, mobile, sortBy = "createtime" } = options;
|
||||
const filter = {};
|
||||
|
||||
if (userId) {
|
||||
filter.userId = userId;
|
||||
}
|
||||
if (name) {
|
||||
// 转义正则特殊字符,避免查询报错或 ReDoS
|
||||
const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
filter["profile.name"] = { $regex: escaped, $options: "i" };
|
||||
}
|
||||
if (mobile) {
|
||||
filter["profile.mobile"] = mobile;
|
||||
}
|
||||
if (userId) {
|
||||
filter.userId = userId;
|
||||
}
|
||||
if (name) {
|
||||
// 转义正则特殊字符,避免查询报错或 ReDoS
|
||||
const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
filter["profile.name"] = { $regex: escaped, $options: "i" };
|
||||
}
|
||||
if (mobile) {
|
||||
filter["profile.mobile"] = mobile;
|
||||
}
|
||||
|
||||
const sortField = sortBy === "updatetime" ? "meta.updatetime" : "meta.createtime";
|
||||
const skip = (page - 1) * pageSize;
|
||||
const [list, total] = await Promise.all([
|
||||
this.find(filter)
|
||||
.sort({ [sortField]: -1 })
|
||||
const sortField = sortBy === "updatetime" ? "meta.updatetime" : "meta.createtime";
|
||||
const skip = (page - 1) * pageSize;
|
||||
const [list, total] = await Promise.all([
|
||||
this.find(filter)
|
||||
.sort({ [sortField]: -1 })
|
||||
.skip(skip)
|
||||
.limit(pageSize)
|
||||
.exec(),
|
||||
|
||||
Reference in New Issue
Block a user