|
@@ -19,24 +19,77 @@ class UserModel {
|
|
|
model = null;
|
|
|
|
|
|
/**
|
|
|
+ * 默认结构
|
|
|
+ *
|
|
|
+ * @var {object}
|
|
|
+ */
|
|
|
+ defaultSchema = {
|
|
|
+ username: {
|
|
|
+ type: String,
|
|
|
+ required: true
|
|
|
+ },
|
|
|
+ email: {
|
|
|
+ type: String,
|
|
|
+ required: true
|
|
|
+ },
|
|
|
+ mobile: {
|
|
|
+ type: String,
|
|
|
+ required: true,
|
|
|
+ validate: {
|
|
|
+ validator: function(v) {
|
|
|
+ return /^1([34578]\d)\d{8}$/.test(v);
|
|
|
+ },
|
|
|
+ message: '{VALUE} is not a valid phone number!'
|
|
|
+ },
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存用户详情结构
|
|
|
+ *
|
|
|
+ * @var {object}
|
|
|
+ */
|
|
|
+ saveInfoSchema = {
|
|
|
+ real_name: {
|
|
|
+ type: String,
|
|
|
+ required: true
|
|
|
+ },
|
|
|
+ company: {
|
|
|
+ type: String,
|
|
|
+ required: true
|
|
|
+ },
|
|
|
+ province: {
|
|
|
+ type: String,
|
|
|
+ required: true
|
|
|
+ },
|
|
|
+ area: {
|
|
|
+ type: Number,
|
|
|
+ required: true
|
|
|
+ },
|
|
|
+ company_type: Number,
|
|
|
+ company_scale: Number,
|
|
|
+ last_login: Number,
|
|
|
+ create_time: Number
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
* 构造函数
|
|
|
*
|
|
|
+ * @param {string} scene
|
|
|
* @return {void}
|
|
|
*/
|
|
|
- constructor() {
|
|
|
+ constructor(scene = 'default') {
|
|
|
let umDB = dbm.getCfgConnection("scConstruct");
|
|
|
- let usersSchema = new mongoose.Schema({
|
|
|
- username: String,
|
|
|
- email: String,
|
|
|
- mobile: String,
|
|
|
- real_name: String,
|
|
|
- company: String,
|
|
|
- province: Number,
|
|
|
- company_type: Number,
|
|
|
- company_scale: Number,
|
|
|
- last_login: Number,
|
|
|
- create_time: Number
|
|
|
- });
|
|
|
+ let schema = {};
|
|
|
+ switch (scene) {
|
|
|
+ case 'saveInfo':
|
|
|
+ schema = this.saveInfoSchema;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ schema = this.defaultSchema;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ let usersSchema = new mongoose.Schema(schema);
|
|
|
this.model = umDB.model('users', usersSchema);
|
|
|
}
|
|
|
|
|
@@ -182,19 +235,20 @@ class UserModel {
|
|
|
if (Object.keys(condition).length <= 0 || Object.keys(updateData).length <= 0) {
|
|
|
return null;
|
|
|
}
|
|
|
- let self = this;
|
|
|
+ let userModel = new this.model();
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
- self.model.update(condition, {$set: updateData}, function(error, result) {
|
|
|
+ let validationError = userModel.validateSync();
|
|
|
+ if (validationError) {
|
|
|
+ reject(validationError);
|
|
|
+ }
|
|
|
+ userModel.update(condition, {$set: updateData}, function(error, result) {
|
|
|
if (error) {
|
|
|
- reject(false);
|
|
|
+ reject(error);
|
|
|
} else {
|
|
|
resolve(result);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|