Upkeep.controller.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import {
  2. Body,
  3. Controller,
  4. Del,
  5. Get,
  6. Inject,
  7. Param,
  8. Post,
  9. Query,
  10. } from '@midwayjs/decorator';
  11. import { BaseController } from 'free-midway-component';
  12. import { UpkeepService } from '../service/Upkeep.service';
  13. import {
  14. CDTO_upkeep,
  15. CVO_upkeep,
  16. FVO_upkeep,
  17. QDTO_upkeep,
  18. QVO_upkeep,
  19. UDTO_upkeep,
  20. UVAO_upkeep,
  21. } from '../interface/Upkeep.interface';
  22. import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
  23. import { Validate } from '@midwayjs/validate';
  24. import { UserUtilService } from '../service/util/user.util';
  25. @ApiTags(['维修表'])
  26. @Controller('/Upkeep')
  27. export class UpkeepController extends BaseController {
  28. @Inject()
  29. service: UpkeepService;
  30. @Inject()
  31. userUtil: UserUtilService;
  32. @Post('/')
  33. @Validate()
  34. @ApiResponse({ type: CVO_upkeep })
  35. async create(@Body() data: CDTO_upkeep) {
  36. // 检查是否创建相同维修数据
  37. await this.userUtil.checkUpkeep(data);
  38. await this.service.createBefore(data);
  39. const dbData = await this.service.create(data);
  40. const result = new CVO_upkeep(dbData);
  41. return result;
  42. }
  43. @Get('/')
  44. @ApiQuery({ name: 'query' })
  45. @ApiResponse({ type: QVO_upkeep })
  46. async query(
  47. @Query() filter: QDTO_upkeep,
  48. @Query('skip') skip: number,
  49. @Query('limit') limit: number
  50. ) {
  51. const list = await this.service.query(filter, { skip, limit });
  52. const data = [];
  53. for (const i of list) {
  54. const newData = new QVO_upkeep(i);
  55. data.push(newData);
  56. }
  57. const total = await this.service.count(filter);
  58. return { data, total };
  59. }
  60. @Get('/:id')
  61. @ApiResponse({ type: FVO_upkeep })
  62. async fetch(@Param('id') id: string) {
  63. const data = await this.service.fetch(id);
  64. const result = new FVO_upkeep(data);
  65. return result;
  66. }
  67. @Post('/:id')
  68. @Validate()
  69. @ApiResponse({ type: UVAO_upkeep })
  70. async update(@Param('id') id: string, @Body() body: UDTO_upkeep) {
  71. const result = await this.service.update(id, body);
  72. return result;
  73. }
  74. @Del('/:id')
  75. @Validate()
  76. async delete(@Param('id') id: string) {
  77. await this.service.delete(id);
  78. return 'ok';
  79. }
  80. async createMany(...args: any[]) {
  81. throw new Error('Method not implemented.');
  82. }
  83. async updateMany(...args: any[]) {
  84. throw new Error('Method not implemented.');
  85. }
  86. async deleteMany(...args: any[]) {
  87. throw new Error('Method not implemented.');
  88. }
  89. }