lrf402788946 %!s(int64=4) %!d(string=hai) anos
pai
achega
99f35b33d2
Modificáronse 1 ficheiros con 23 adicións e 21 borrados
  1. 23 21
      app/service/user.js

+ 23 - 21
app/service/user.js

@@ -60,34 +60,36 @@ class UserService extends CrudService {
     return res;
   }
 
-  async update({ id }, { name, mobile, passwd, openid, status, type }) {
+  async update({ id }, body) {
+    const { name, mobile, passwd, openid, status, type } = body;
     assert(id, '缺少部分信息项');
     const user = await this.model.findById(id);
     if (!user) {
       throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '用户信息不存在');
     }
     if (passwd) {
-      user.passwd = { secret: passwd };
+      body.passwd = { secret: passwd };
     }
-    if (name) {
-      user.name = name;
-    }
-    if (mobile) {
-      user.mobile = mobile;
-    }
-    if (openid) {
-      user.openid = openid;
-    }
-    if (status) {
-      user.status = status;
-    } else {
-      user.status = '1';
-    }
-    if (type) {
-      user.type = type;
-    }
-    await user.save();
-    return user;
+    return await this.model.updateOne({ _id: id }, body);
+    // if (name) {
+    //   user.name = name;
+    // }
+    // if (mobile) {
+    //   user.mobile = mobile;
+    // }
+    // if (openid) {
+    //   user.openid = openid;
+    // }
+    // if (status) {
+    //   user.status = status;
+    // } else {
+    //   user.status = '1';
+    // }
+    // if (type) {
+    //   user.type = type;
+    // }
+    // await user.save();
+    // return user;
   }
 
   // 学校注册