ai review
This commit is contained in:
+6
-8
@@ -9,8 +9,6 @@ class MongoDBSchema {
|
||||
constructor() {
|
||||
this.dbConnection = null;
|
||||
this.User = null;
|
||||
this.EscortRecord = null;
|
||||
this.Hospital = null;
|
||||
}
|
||||
|
||||
init() {
|
||||
@@ -18,22 +16,22 @@ class MongoDBSchema {
|
||||
|
||||
this.dbConnection = mongoose.createConnection(config.mongodb.str, config.mongodb.option);
|
||||
this.dbConnection.on("error", () => {
|
||||
logger.error.bind(logger, "...mongodb connect error ...")
|
||||
logger.error("...mongodb connect error ...");
|
||||
});
|
||||
this.dbConnection.on("connected", async () => {
|
||||
logger.info("Mongodb: " + config.mongodb.str + " connected");
|
||||
logger.info(`Mongodb: ${config.mongodb.host}/${config.mongodb.option.dbName} connected`);
|
||||
});
|
||||
this.dbConnection.on("disconnected", () =>
|
||||
logger.warn("Mongodb: " + config.mongodb.str + " disconnected")
|
||||
logger.warn(`Mongodb: ${config.mongodb.host}/${config.mongodb.option.dbName} disconnected`)
|
||||
);
|
||||
this.dbConnection.on("reconnected", () =>
|
||||
logger.info("Mongodb: " + config.mongodb.str + " reconnected")
|
||||
logger.info(`Mongodb: ${config.mongodb.host}/${config.mongodb.option.dbName} reconnected`)
|
||||
);
|
||||
this.dbConnection.on("disconnecting", () =>
|
||||
logger.warn("Mongodb: " + config.mongodb.str + " disconnecting")
|
||||
logger.warn(`Mongodb: ${config.mongodb.host}/${config.mongodb.option.dbName} disconnecting`)
|
||||
);
|
||||
this.dbConnection.on("close", () =>
|
||||
logger.warn("Mongodb: " + config.mongodb.str + " closed")
|
||||
logger.warn(`Mongodb: ${config.mongodb.host}/${config.mongodb.option.dbName} closed`)
|
||||
);
|
||||
|
||||
this.User = this.dbConnection.model('user', UserSchema)
|
||||
|
||||
@@ -88,30 +88,6 @@ const UserSchema = mongoose.Schema(
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* 根据用户标识信息查找用户
|
||||
*
|
||||
* 支持通过手机号、邮箱、token或微信unionid查找用户
|
||||
*
|
||||
* @param {Object} _user - 包含查找条件的用户对象
|
||||
* @param {Function} cb - 可选的回调函数
|
||||
* @returns {Promise<Object|null>} 找到的用户对象或null
|
||||
*/
|
||||
UserSchema.statics.findUser = async function (_user, cb) {
|
||||
let filter = {};
|
||||
if (_user.profile && _user.profile.mobile) {
|
||||
filter = { "profile.mobile": _user.profile.mobile };
|
||||
} else if (_user.profile && _user.profile.email) {
|
||||
filter = { "profile.email": new RegExp(_user.profile.email, "i") };
|
||||
} else if (_user.security && _user.security.token) {
|
||||
filter = { "security.token": new RegExp(_user.security.token, "i") };
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return await this.findOne(filter, cb);
|
||||
};
|
||||
|
||||
/**
|
||||
* 设置/更新用户信息
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user