zs 7 months ago
parent
commit
ff1cf0e4b4

+ 12 - 0
src/controller/users/applyCompany.controller.ts

@@ -37,6 +37,18 @@ export class ApplyCompanyController implements BaseController {
     return result;
   }
 
+  @Get('/list')
+  async list(@Query() query: object) {
+    const qobj = omit(query, ['skip', 'limit']);
+    const others = pick(query, ['skip', 'limit']);
+    const { data, total } = await this.service.query(qobj, others);
+    const list = [];
+    for (const i of data) {
+      list.push(await this.service.fillName(i));
+    }
+    return { data: list, total };
+  }
+
   @Get('/:id')
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_applyCompany })

+ 26 - 1
src/service/users/applyCompany.service.ts

@@ -1,10 +1,35 @@
-import { Provide } from '@midwayjs/core';
+import { Inject, Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
 import { ApplyCompany } from '../../entity/users/applyCompany.entity';
 import { BaseServiceV2 } from '../../frame/BaseServiceV2';
+import { get } from 'lodash';
+import { CompanyService } from './company.service';
+import { UserService } from '../system/user.service';
 @Provide()
 export class ApplyCompanyService extends BaseServiceV2 {
   @InjectEntityModel(ApplyCompany)
   model: Repository<ApplyCompany>;
+
+  @Inject()
+  companyService: CompanyService;
+
+  @Inject()
+  userService: UserService;
+
+  /**
+   * 填充
+   * @param {object} data 数据
+   */
+  async fillName(data) {
+    const { company, user } = data;
+    // 公司名称
+    const companyInfo = await this.companyService.fetch({ id: company });
+    if (companyInfo) data = { ...data, company_name: get(companyInfo, 'name') };
+    // 用户名称
+    const userInfo = await this.userService.fetch({ id: user });
+    if (userInfo) data = { ...data, user_name: get(userInfo, 'nick_name') };
+
+    return data;
+  }
 }