瀏覽代碼

修改认证

zs 8 月之前
父節點
當前提交
02833f04fe
共有 1 個文件被更改,包括 7 次插入6 次删除
  1. 7 6
      src/service/users/applyCompany.service.ts

+ 7 - 6
src/service/users/applyCompany.service.ts

@@ -17,7 +17,6 @@ export class ApplyCompanyService extends BaseServiceV2 {
 
   @Inject()
   userService: UserService;
-
   // 认领检查
   async createExamine(data) {
     const { user } = data;
@@ -34,13 +33,15 @@ export class ApplyCompanyService extends BaseServiceV2 {
     const company = await this.companyService.fetch({ user: get(result, 'user') });
     if (company) throw new ServiceError(ErrorCode.SERVICE_APPLY);
     else {
-      // 修改企业用户id
-      await this.companyService.update({ id: get(result, 'company') }, { id: get(result, 'company'), user: get(result, 'user') });
       // 查询用户角色
       const userInfo = await this.userService.fetch({ id: get(result, 'user') });
-      const is_update = userInfo.role.find(i => i === 'Company');
-      // 如果没有企业角色 增加一个企业角色
-      if (!is_update) await this.userService.fetch({ id: get(result, 'user'), role: [...userInfo.role, ['Company']] });
+      if (userInfo) {
+        const is_update = userInfo.role.find(i => i === 'Company');
+        // 如果没有企业角色 增加一个企业角色
+        if (!is_update) await this.userService.update({ id: get(result, 'user') }, { id: get(result, 'user'), role: [...userInfo.role, 'Company'] });
+        // 修改企业用户id
+        await this.companyService.update({ id: get(result, 'company') }, { id: get(result, 'company'), user: get(result, 'user') });
+      } else throw new ServiceError(ErrorCode.USER_NOT_FOUND);
     }
   }