matchExt.controller.ts 2.3 KB

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