support.controller.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { Controller, Inject, Get, Param, Post, Body, Del, Query } from '@midwayjs/core';
  2. import { SupportService } from '../../service/platform/support.service';
  3. import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
  4. import { Validate } from '@midwayjs/validate';
  5. import { omit, pick } from 'lodash';
  6. import { ServiceError, ErrorCode } from '../../error/service.error';
  7. import { BaseController } from '../../frame/BaseController';
  8. import { QVO_support, FVO_support, CVO_support, UVAO_support } from '../../interface/platform/support.interface';
  9. const namePrefix = '服务支撑';
  10. @ApiTags(['服务支撑'])
  11. @Controller('/support', { tagName: namePrefix })
  12. export class supportController implements BaseController {
  13. @Inject()
  14. service: SupportService;
  15. @Get('/')
  16. @ApiTags('列表查询')
  17. @ApiQuery({ name: 'query' })
  18. @ApiResponse({ type: QVO_support })
  19. async index(@Query() query: object) {
  20. const qobj = omit(query, ['skip', 'limit']);
  21. const others = pick(query, ['skip', 'limit']);
  22. const qbr = this.service.queryBuilder(qobj);
  23. const result = await this.service.query(qbr, others);
  24. return result;
  25. }
  26. @Get('/:id')
  27. @ApiTags('单查询')
  28. @ApiResponse({ type: FVO_support })
  29. async fetch(@Param('id') id: number) {
  30. const qbr = this.service.queryBuilder({ id });
  31. const data = await this.service.fetch(qbr);
  32. const result = new FVO_support(data);
  33. return result;
  34. }
  35. @Post('/', { routerName: `创建${namePrefix}` })
  36. @ApiTags('创建数据')
  37. @Validate()
  38. @ApiResponse({ type: CVO_support })
  39. async create(@Body() data: object) {
  40. const dbData = await this.service.create(data);
  41. const result = new CVO_support(dbData);
  42. return result;
  43. }
  44. @Post('/:id', { routerName: `修改${namePrefix}` })
  45. @ApiTags('修改数据')
  46. @Validate()
  47. @ApiResponse({ type: UVAO_support })
  48. async update(@Param('id') id: number, @Body() data: object) {
  49. if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
  50. const result = await this.service.update({ id }, data);
  51. return result;
  52. }
  53. @Del('/:id', { routerName: `删除${namePrefix}` })
  54. @ApiTags('删除数据')
  55. @Validate()
  56. async delete(@Param('id') id: number) {
  57. if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
  58. const result = await this.service.delete({ id });
  59. return result;
  60. }
  61. }