guhongwei hace 4 años
padre
commit
6c713d1841
Se han modificado 3 ficheros con 16 adiciones y 0 borrados
  1. 2 0
      app/controller/.user.js
  2. 1 0
      app/model/user.js
  3. 13 0
      app/service/user.js

+ 2 - 0
app/controller/.user.js

@@ -13,6 +13,7 @@ module.exports = {
       "pid",
       "code",
       "remark",
+      "isdel",
     ],
   },
   destroy: {
@@ -34,6 +35,7 @@ module.exports = {
       "pid",
       "code",
       "remark",
+      "isdel",
     ],
   },
   show: {

+ 1 - 0
app/model/user.js

@@ -16,6 +16,7 @@ const UserSchema = {
   deptname: { type: String, required: false }, // 机构名称
   remark: { type: String, required: false }, // 备注
   code: { type: String, required: false }, // 邀请码
+  isdel: { type: String, required: false, default: '0' }, // 0=>未删除;1=>已删除
 };
 
 

+ 13 - 0
app/service/user.js

@@ -174,6 +174,19 @@ class UserService extends CrudService {
       .limit(Number(limit));
     return { data, total };
   }
+  // 重写删除方法
+  /**
+   * 根据id删除=>修改isdel为1
+   * @param {Object} {id} 只接收id,不过需要解构,因为是object形式过来的
+   */
+  async delete({ id }) {
+    const data = await this.model.findById(id);
+    if (!data) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
+    }
+    const res = await data.update({ isdel: '1' });
+    return res;
+  }
 }
 
 module.exports = UserService;