match.controller.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { MatchService } from '../../service/platform/match.service';
  2. import { CVO_match, FVO_match, QVO_match, UVAO_match } from '../../interface/platform/match.interface';
  3. import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
  4. import { Validate } from '@midwayjs/validate';
  5. import { Controller, Inject, Get, Param, Post, Body, Del, Query } from '@midwayjs/core';
  6. import { omit, pick } from 'lodash';
  7. import { ServiceError, ErrorCode } from '../../error/service.error';
  8. import { BaseController } from '../../frame/BaseController';
  9. import { ServiceUtilService } from '../../service/serviceUtil.service';
  10. const namePrefix = '创新大赛';
  11. @ApiTags(['创新大赛'])
  12. @Controller('/match', { tagName: namePrefix })
  13. export class MatchController implements BaseController {
  14. @Inject()
  15. service: MatchService;
  16. @Inject()
  17. serviceUtil: ServiceUtilService;
  18. @Get('/')
  19. @ApiTags('列表查询')
  20. @ApiQuery({ name: 'query' })
  21. @ApiResponse({ type: QVO_match })
  22. async index(@Query() query: object) {
  23. const qobj = omit(query, ['skip', 'limit']);
  24. const others: any = pick(query, ['skip', 'limit']);
  25. others.order = { order_num: 'ASC' };
  26. const result = await this.service.query(qobj, others);
  27. return result;
  28. }
  29. @Get('/:id')
  30. @ApiTags('单查询')
  31. @ApiResponse({ type: FVO_match })
  32. async fetch(@Param('id') id: number) {
  33. const data = await this.service.fetch({ id });
  34. const result = new FVO_match(data);
  35. return result;
  36. }
  37. @Post('/', { routerName: `创建${namePrefix}` })
  38. @ApiTags('创建数据')
  39. @Validate()
  40. @ApiResponse({ type: CVO_match })
  41. async create(@Body() data: object) {
  42. const dbData = await this.service.create(data);
  43. const result = new CVO_match(dbData);
  44. return result;
  45. }
  46. @Post('/:id', { routerName: `修改${namePrefix}` })
  47. @ApiTags('修改数据')
  48. @Validate()
  49. @ApiResponse({ type: UVAO_match })
  50. async update(@Param('id') id: number, @Body() data: object) {
  51. if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
  52. const result = await this.service.update({ id }, data);
  53. return result;
  54. }
  55. @Del('/:id', { routerName: `删除${namePrefix}` })
  56. @ApiTags('删除数据')
  57. @Validate()
  58. async delete(@Param('id') id: number) {
  59. if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
  60. const result = await this.service.delete({ id });
  61. return result;
  62. }
  63. @Get('/detail/:id')
  64. @ApiResponse({ type: FVO_match })
  65. async detail(@Param('id') id: string) {
  66. let data = await this.service.fetch({ id });
  67. data = await this.serviceUtil.fillOnwer(data);
  68. data = await this.serviceUtil.fillCollection(data, 'match');
  69. return data;
  70. }
  71. }