|
@@ -3,10 +3,11 @@ import { CVO_match, FVO_match, QVO_match, UVAO_match } from '../../interface/pla
|
|
import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
|
|
import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
|
|
import { Validate } from '@midwayjs/validate';
|
|
import { Validate } from '@midwayjs/validate';
|
|
import { Controller, Inject, Get, Param, Post, Body, Del, Query } from '@midwayjs/core';
|
|
import { Controller, Inject, Get, Param, Post, Body, Del, Query } from '@midwayjs/core';
|
|
-import { omit, pick } from 'lodash';
|
|
|
|
|
|
+import { get, omit, pick } from 'lodash';
|
|
import { ServiceError, ErrorCode } from '../../error/service.error';
|
|
import { ServiceError, ErrorCode } from '../../error/service.error';
|
|
import { BaseController } from '../../frame/BaseController';
|
|
import { BaseController } from '../../frame/BaseController';
|
|
import { ServiceUtilService } from '../../service/serviceUtil.service';
|
|
import { ServiceUtilService } from '../../service/serviceUtil.service';
|
|
|
|
+import { MatchExtService } from '../../service/match/matchExt.service';
|
|
const namePrefix = '创新大赛';
|
|
const namePrefix = '创新大赛';
|
|
@ApiTags(['创新大赛'])
|
|
@ApiTags(['创新大赛'])
|
|
@Controller('/match', { tagName: namePrefix })
|
|
@Controller('/match', { tagName: namePrefix })
|
|
@@ -15,6 +16,8 @@ export class MatchController implements BaseController {
|
|
service: MatchService;
|
|
service: MatchService;
|
|
@Inject()
|
|
@Inject()
|
|
serviceUtil: ServiceUtilService;
|
|
serviceUtil: ServiceUtilService;
|
|
|
|
+ @Inject()
|
|
|
|
+ matchExtService: MatchExtService;
|
|
@Get('/')
|
|
@Get('/')
|
|
@ApiTags('列表查询')
|
|
@ApiTags('列表查询')
|
|
@ApiQuery({ name: 'query' })
|
|
@ApiQuery({ name: 'query' })
|
|
@@ -41,7 +44,20 @@ export class MatchController implements BaseController {
|
|
@Validate()
|
|
@Validate()
|
|
@ApiResponse({ type: CVO_match })
|
|
@ApiResponse({ type: CVO_match })
|
|
async create(@Body() data: object) {
|
|
async create(@Body() data: object) {
|
|
- const dbData = await this.service.create(data);
|
|
|
|
|
|
+ const extColumns = ['ext_info', 'ext_finals']
|
|
|
|
+ const matchData = omit(data, extColumns)
|
|
|
|
+ let extData = pick(data, extColumns)
|
|
|
|
+ const dbData = await this.service.create(matchData);
|
|
|
|
+ // 如果类型是4,需要特殊处理下,补充赛事拓展表
|
|
|
|
+ if (get(matchData, 'type') === '4') {
|
|
|
|
+ // 查查有没有拓展数据,有就不创建了
|
|
|
|
+ const match_id = dbData.id
|
|
|
|
+ const ed = await this.matchExtService.fetch({ match_id })
|
|
|
|
+ if (!ed) {
|
|
|
|
+ extData = { match_id, ...extData }
|
|
|
|
+ await this.matchExtService.create(extData)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
const result = new CVO_match(dbData);
|
|
const result = new CVO_match(dbData);
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
@@ -52,8 +68,15 @@ export class MatchController implements BaseController {
|
|
@ApiResponse({ type: UVAO_match })
|
|
@ApiResponse({ type: UVAO_match })
|
|
async update(@Param('id') id: number, @Body() data: object) {
|
|
async update(@Param('id') id: number, @Body() data: object) {
|
|
if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
|
|
if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
|
|
- const result = await this.service.update({ id }, data);
|
|
|
|
|
|
+ const extColumns = ['ext_info', 'ext_finals']
|
|
|
|
+ const matchData = omit(data, extColumns)
|
|
|
|
+ let extData = pick(data, extColumns)
|
|
|
|
+ const result = await this.service.update({ id }, matchData);
|
|
await this.service.updateProject({ id }, data);
|
|
await this.service.updateProject({ id }, data);
|
|
|
|
+ // 如果类型是4,需要特殊处理下,补充赛事拓展表,不需要修改状态和赛事id
|
|
|
|
+ if (get(matchData, 'type') === '4') {
|
|
|
|
+ await this.matchExtService.update({ match_id: id }, extData)
|
|
|
|
+ }
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|