footplate.controller.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { Controller, Inject, Get, Param, Post, Body, Del, Query } from '@midwayjs/core';
  2. import { FootplateService } from '../../service/platform/footplate.service';
  3. import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
  4. import { Validate } from '@midwayjs/validate';
  5. import { omit, pick } from 'lodash';
  6. import { BaseController } from '../../frame/BaseController';
  7. import { ServiceError, ErrorCode } from '../../error/service.error';
  8. import { QVO_footplate, FVO_footplate, CVO_footplate, UVAO_footplate } from '../../interface/platform/footplate.interface';
  9. const namePrefix = '中试平台';
  10. @ApiTags(['中试平台'])
  11. @Controller('/footplate', { tagName: namePrefix })
  12. export class footplateController implements BaseController {
  13. @Inject()
  14. service: FootplateService;
  15. @Get('/')
  16. @ApiTags('列表查询')
  17. @ApiQuery({ name: 'query' })
  18. @ApiResponse({ type: QVO_footplate })
  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_footplate })
  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_footplate(data);
  33. return result;
  34. }
  35. @Post('/', { routerName: `创建${namePrefix}` })
  36. @ApiTags('创建数据')
  37. @Validate()
  38. @ApiResponse({ type: CVO_footplate })
  39. async create(@Body() data: object) {
  40. const dbData = await this.service.create(data);
  41. const result = new CVO_footplate(dbData);
  42. return result;
  43. }
  44. @Post('/:id', { routerName: `修改${namePrefix}` })
  45. @ApiTags('修改数据')
  46. @Validate()
  47. @ApiResponse({ type: UVAO_footplate })
  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. }