Browse Source

修改特殊身份认证

zs 8 months ago
parent
commit
85e43c638c

+ 4 - 3
src/controller/users/association.controller.ts

@@ -3,10 +3,10 @@ import { AssociationService } from '../../service/users/association.service';
 import { CVO_association, FVO_association, QVO_association, UVAO_association } from '../../interface/users/association.interface';
 import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
-import { UtilService } from '../../service/util.service';
 import { BaseController } from '../../frame/BaseController';
 import { omit, pick } from 'lodash';
 import { ErrorCode, ServiceError } from '../../error/service.error';
+import { ServiceUtilService } from '../../service/serviceUtil.service';
 const namePrefix = '商协会';
 @ApiTags(['商协会'])
 @Controller('/association', { tagName: namePrefix })
@@ -15,7 +15,7 @@ export class AssociationController implements BaseController {
   service: AssociationService;
 
   @Inject()
-  utilService: UtilService;
+  serviceUtil: ServiceUtilService;
 
   @Get('/')
   @ApiTags('列表查询')
@@ -43,6 +43,7 @@ export class AssociationController implements BaseController {
   @ApiResponse({ type: CVO_association })
   async create(@Body() data: object) {
     const dbData = await this.service.create(data);
+    this.serviceUtil.fillIdentity(data, 'Association');
     const result = new CVO_association(dbData);
     return result;
   }
@@ -54,7 +55,7 @@ export class AssociationController implements BaseController {
   async update(@Param('id') id: number, @Body() data: object) {
     if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
     const result = await this.service.update({ id }, data);
-    await this.utilService.updateUserAfter(id, data, 'Association');
+    this.serviceUtil.fillIdentity(data, 'Association');
     return result;
   }
 

+ 3 - 6
src/controller/users/company.controller.ts

@@ -1,9 +1,8 @@
 import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/core';
 import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
-import { UtilService } from '../../service/util.service';
 import { BaseController } from '../../frame/BaseController';
-import { get, omit, pick } from 'lodash';
+import { omit, pick } from 'lodash';
 import { ErrorCode, ServiceError } from '../../error/service.error';
 import { CompanyService } from '../../service/users/company.service';
 import { CVO_company, FVO_company, QVO_company, UVAO_company } from '../../interface/users/company.interface';
@@ -16,9 +15,6 @@ export class CompanyController implements BaseController {
   @Inject()
   service: CompanyService;
 
-  @Inject()
-  utilService: UtilService;
-
   @Inject()
   ctx: Context;
 
@@ -51,6 +47,7 @@ export class CompanyController implements BaseController {
   @ApiResponse({ type: CVO_company })
   async create(@Body() data: object) {
     const dbData = await this.service.create(data);
+    await this.serviceUtil.fillIdentity(data, 'Company');
     const result = new CVO_company(dbData);
     return result;
   }
@@ -62,7 +59,7 @@ export class CompanyController implements BaseController {
   async update(@Param('id') id: number, @Body() data: object) {
     if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
     const result = await this.service.update({ id }, data);
-    await this.utilService.updateUserAfter(id, data, 'Company');
+    await this.serviceUtil.fillIdentity(data, 'Company');
     return result;
   }
 

+ 4 - 3
src/controller/users/competition.controller.ts

@@ -1,12 +1,12 @@
 import { Body, Controller, Del, Get, Inject, Param, Post } from '@midwayjs/core';
 import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
-import { UtilService } from '../../service/util.service';
 import { BaseController } from '../../frame/BaseController';
 import { omit, pick } from 'lodash';
 import { ErrorCode, ServiceError } from '../../error/service.error';
 import { CompetitionService } from '../../service/users/competition.service';
 import { CVO_competition, FVO_competition, QVO_competition, UVAO_competition } from '../../interface/users/competition.interface';
+import { ServiceUtilService } from '../../service/serviceUtil.service';
 const namePrefix = '创新大赛管理人';
 @ApiTags(['创新大赛管理人'])
 @Controller('/competition', { tagName: namePrefix })
@@ -15,7 +15,7 @@ export class CompetitionController implements BaseController {
   service: CompetitionService;
 
   @Inject()
-  utilService: UtilService;
+  serviceUtil: ServiceUtilService;
 
   @Get('/')
   @ApiTags('列表查询')
@@ -43,6 +43,7 @@ export class CompetitionController implements BaseController {
   @ApiResponse({ type: CVO_competition })
   async create(@Body() data: object) {
     const dbData = await this.service.create(data);
+    this.serviceUtil.fillIdentity(data, 'Competition');
     const result = new CVO_competition(dbData);
     return result;
   }
@@ -54,7 +55,7 @@ export class CompetitionController implements BaseController {
   async update(@Param('id') id: number, @Body() data: object) {
     if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
     const result = await this.service.update({ id }, data);
-    await this.utilService.updateUserAfter(id, data, 'Association');
+    this.serviceUtil.fillIdentity(data, 'Competition');
     return result;
   }
 

+ 3 - 2
src/controller/users/expert.controller.ts

@@ -3,7 +3,7 @@ import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
 import { UtilService } from '../../service/util.service';
 import { BaseController } from '../../frame/BaseController';
-import { get, omit, pick } from 'lodash';
+import { omit, pick } from 'lodash';
 import { ErrorCode, ServiceError } from '../../error/service.error';
 import { ExpertService } from '../../service/users/expert.service';
 import { Context } from '@midwayjs/koa';
@@ -49,6 +49,7 @@ export class ExpertController implements BaseController {
   @ApiResponse({ type: CVO_expert })
   async create(@Body() data: object) {
     const dbData = await this.service.create(data);
+    this.serviceUtil.fillIdentity(data, 'Expert');
     const result = new CVO_expert(dbData);
     return result;
   }
@@ -60,7 +61,7 @@ export class ExpertController implements BaseController {
   async update(@Param('id') id: number, @Body() data: object) {
     if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
     const result = await this.service.update({ id }, data);
-    await this.utilService.updateUserAfter(id, data, 'Association');
+    this.serviceUtil.fillIdentity(data, 'Expert');
     return result;
   }
 

+ 4 - 3
src/controller/users/incubator.controller.ts

@@ -1,13 +1,13 @@
 import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/core';
 import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
-import { UtilService } from '../../service/util.service';
 import { BaseController } from '../../frame/BaseController';
 import { omit, pick } from 'lodash';
 import { ErrorCode, ServiceError } from '../../error/service.error';
 import { Context } from '@midwayjs/koa';
 import { IncubatorService } from '../../service/users/incubator.service';
 import { QVO_incubator, FVO_incubator, CVO_incubator, UVAO_incubator } from '../../interface/users/incubator.interface';
+import { ServiceUtilService } from '../../service/serviceUtil.service';
 const namePrefix = '孵化器';
 @ApiTags(['孵化器'])
 @Controller('/incubator', { tagName: namePrefix })
@@ -18,7 +18,7 @@ export class IncubatorController implements BaseController {
   ctx: Context;
 
   @Inject()
-  utilService: UtilService;
+  serviceUtil: ServiceUtilService;
 
   @Get('/')
   @ApiTags('列表查询')
@@ -46,6 +46,7 @@ export class IncubatorController implements BaseController {
   @ApiResponse({ type: CVO_incubator })
   async create(@Body() data: object) {
     const dbData = await this.service.create(data);
+    this.serviceUtil.fillIdentity(data, 'Incubator');
     const result = new CVO_incubator(dbData);
     return result;
   }
@@ -57,7 +58,7 @@ export class IncubatorController implements BaseController {
   async update(@Param('id') id: number, @Body() data: object) {
     if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
     const result = await this.service.update({ id }, data);
-    await this.utilService.updateUserAfter(id, data, 'Association');
+    this.serviceUtil.fillIdentity(data, 'Incubator');
     return result;
   }
 

+ 4 - 3
src/controller/users/investment.controller.ts

@@ -1,13 +1,13 @@
 import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/core';
 import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
-import { UtilService } from '../../service/util.service';
 import { BaseController } from '../../frame/BaseController';
 import { omit, pick } from 'lodash';
 import { ErrorCode, ServiceError } from '../../error/service.error';
 import { Context } from '@midwayjs/koa';
 import { InvestmentService } from '../../service/users/investment.service';
 import { QVO_investment, FVO_investment, CVO_investment, UVAO_investment } from '../../interface/users/investment.interface';
+import { ServiceUtilService } from '../../service/serviceUtil.service';
 const namePrefix = '投资人';
 @ApiTags(['投资人'])
 @Controller('/investment', { tagName: namePrefix })
@@ -18,7 +18,7 @@ export class InvestmentController implements BaseController {
   ctx: Context;
 
   @Inject()
-  utilService: UtilService;
+  serviceUtil: ServiceUtilService;
 
   @Get('/')
   @ApiTags('列表查询')
@@ -46,6 +46,7 @@ export class InvestmentController implements BaseController {
   @ApiResponse({ type: CVO_investment })
   async create(@Body() data: object) {
     const dbData = await this.service.create(data);
+    this.serviceUtil.fillIdentity(data, 'Investment');
     const result = new CVO_investment(dbData);
     return result;
   }
@@ -57,7 +58,7 @@ export class InvestmentController implements BaseController {
   async update(@Param('id') id: number, @Body() data: object) {
     if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
     const result = await this.service.update({ id }, data);
-    await this.utilService.updateUserAfter(id, data, 'Association');
+    this.serviceUtil.fillIdentity(data, 'Investment');
     return result;
   }
 

+ 4 - 3
src/controller/users/state.controller.ts

@@ -1,13 +1,13 @@
 import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/core';
 import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
-import { UtilService } from '../../service/util.service';
 import { BaseController } from '../../frame/BaseController';
 import { omit, pick } from 'lodash';
 import { ErrorCode, ServiceError } from '../../error/service.error';
 import { Context } from '@midwayjs/koa';
 import { InvestmentService } from '../../service/users/investment.service';
 import { QVO_state, FVO_state, CVO_state, UVAO_state } from '../../interface/users/state.interface';
+import { ServiceUtilService } from '../../service/serviceUtil.service';
 const namePrefix = '政府部门';
 @ApiTags(['政府部门'])
 @Controller('/state', { tagName: namePrefix })
@@ -18,7 +18,7 @@ export class StateController implements BaseController {
   ctx: Context;
 
   @Inject()
-  utilService: UtilService;
+  serviceUtil: ServiceUtilService;
 
   @Get('/')
   @ApiTags('列表查询')
@@ -46,6 +46,7 @@ export class StateController implements BaseController {
   @ApiResponse({ type: CVO_state })
   async create(@Body() data: object) {
     const dbData = await this.service.create(data);
+    this.serviceUtil.fillIdentity(data, 'State');
     const result = new CVO_state(dbData);
     return result;
   }
@@ -57,7 +58,7 @@ export class StateController implements BaseController {
   async update(@Param('id') id: number, @Body() data: object) {
     if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
     const result = await this.service.update({ id }, data);
-    await this.utilService.updateUserAfter(id, data, 'Association');
+    this.serviceUtil.fillIdentity(data, 'State');
     return result;
   }
 

+ 4 - 3
src/controller/users/unit.controller.ts

@@ -1,13 +1,13 @@
 import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/core';
 import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
-import { UtilService } from '../../service/util.service';
 import { BaseController } from '../../frame/BaseController';
 import { omit, pick } from 'lodash';
 import { ErrorCode, ServiceError } from '../../error/service.error';
 import { Context } from '@midwayjs/koa';
 import { UnitService } from '../../service/users/unit.service';
 import { QVO_unit, FVO_unit, CVO_unit, UVAO_unit } from '../../interface/users/unit.interface';
+import { ServiceUtilService } from '../../service/serviceUtil.service';
 const namePrefix = '科研机构';
 @ApiTags(['科研机构'])
 @Controller('/unit', { tagName: namePrefix })
@@ -18,7 +18,7 @@ export class UnitController implements BaseController {
   ctx: Context;
 
   @Inject()
-  utilService: UtilService;
+  serviceUtil: ServiceUtilService;
 
   @Get('/')
   @ApiTags('列表查询')
@@ -46,6 +46,7 @@ export class UnitController implements BaseController {
   @ApiResponse({ type: CVO_unit })
   async create(@Body() data: object) {
     const dbData = await this.service.create(data);
+    this.serviceUtil.fillIdentity(data, 'Unit');
     const result = new CVO_unit(dbData);
     return result;
   }
@@ -57,7 +58,7 @@ export class UnitController implements BaseController {
   async update(@Param('id') id: number, @Body() data: object) {
     if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
     const result = await this.service.update({ id }, data);
-    await this.utilService.updateUserAfter(id, data, 'Association');
+    this.serviceUtil.fillIdentity(data, 'Unit');
     return result;
   }
 

+ 14 - 1
src/service/serviceUtil.service.ts

@@ -1,5 +1,5 @@
 import { Inject, Provide } from '@midwayjs/core';
-import { get } from 'lodash';
+import { get, union } from 'lodash';
 import { CollectionService } from './platform/collection.service';
 import { UserService } from './system/user.service';
 import { Context } from '@midwayjs/koa';
@@ -49,4 +49,17 @@ export class ServiceUtilService {
     const matchInfo = await this.matchService.fetch({ id: match });
     if (matchInfo) data = { ...data, matchInfo };
   }
+
+  /**
+   * 用户创建特殊身份认证
+   */
+  async fillIdentity(data, type) {
+    if (data && get(data, 'user')) {
+      const dataUser = await this.userService.fetch({ id: get(data, 'user') });
+      if (dataUser) {
+        const role = union(get(dataUser, 'role'), [type]);
+        await this.userService.update(get(dataUser, 'id'), { id: get(dataUser, 'id'), role, status: '0' });
+      }
+    }
+  }
 }