lrf 2 年之前
父節點
當前提交
8c72122a99
共有 1 個文件被更改,包括 9 次插入0 次删除
  1. 9 0
      app/service/user/user.js

+ 9 - 0
app/service/user/user.js

@@ -10,6 +10,15 @@ class UserService extends CrudService {
     super(ctx, 'user');
     this.model = this.ctx.model.User.User;
   }
+  async beforeCreate(data) {
+    const phone = _.get(data, 'phone');
+    if (phone) {
+      const num = await this.model.count({ phone });
+      if (num > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '该手机号已注册');
+    }
+    return data;
+  }
+
   async resetPwd({ id }, { password }) {
     const data = await this.model.findById(id);
     if (!data) throw new BusinessError(ErrorCode.USER_NOT_EXIST);