cpcMessage.controller.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 { CpcMessageService } from '../service/cpcMessage.service';
  13. import {
  14. CDTO_cpcMessage,
  15. CVO_cpcMessage,
  16. FVO_cpcMessage,
  17. QDTO_cpcMessage,
  18. QVO_cpcMessage,
  19. UDTO_cpcMessage,
  20. UVAO_cpcMessage,
  21. ImportDTO,
  22. } from '../interface/cpcMessage.interface';
  23. import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
  24. import { Validate } from '@midwayjs/validate';
  25. @ApiTags(['国知局反馈信息'])
  26. @Controller('/cpcMessage')
  27. export class CpcMessageController extends BaseController {
  28. @Inject()
  29. service: CpcMessageService;
  30. @Post('/')
  31. @Validate()
  32. @ApiResponse({ type: CVO_cpcMessage })
  33. async create(@Body() data: CDTO_cpcMessage) {
  34. const dbData = await this.service.create(data);
  35. const result = new CVO_cpcMessage(dbData);
  36. return result;
  37. }
  38. @Get('/')
  39. @ApiQuery({ name: 'query' })
  40. @ApiResponse({ type: QVO_cpcMessage })
  41. async query(
  42. @Query() filter: QDTO_cpcMessage,
  43. @Query('skip') skip: number,
  44. @Query('limit') limit: number
  45. ) {
  46. const list = await this.service.query(filter, { skip, limit });
  47. const data = [];
  48. for (const i of list) {
  49. const newData = new QVO_cpcMessage(i);
  50. data.push(newData);
  51. }
  52. const total = await this.service.count(filter);
  53. return { data, total };
  54. }
  55. @Get('/:id')
  56. @ApiResponse({ type: FVO_cpcMessage })
  57. async fetch(@Param('id') id: string) {
  58. const data = await this.service.fetch(id);
  59. const result = new FVO_cpcMessage(data);
  60. return result;
  61. }
  62. @Post('/:id')
  63. @Validate()
  64. @ApiResponse({ type: UVAO_cpcMessage })
  65. async update(@Param('id') id: string, @Body() body: UDTO_cpcMessage) {
  66. const result = await this.service.updateOne(id, body);
  67. return result;
  68. }
  69. @Del('/:id')
  70. @Validate()
  71. async delete(@Param('id') id: string) {
  72. await this.service.delete(id);
  73. return 'ok';
  74. }
  75. @Post('/import')
  76. @Validate()
  77. async import(@Body() body: ImportDTO) {
  78. const result = await this.service.import(body);
  79. return result;
  80. }
  81. async createMany(...args: any[]) {
  82. throw new Error('Method not implemented.');
  83. }
  84. async updateMany(...args: any[]) {
  85. throw new Error('Method not implemented.');
  86. }
  87. async deleteMany(...args: any[]) {
  88. throw new Error('Method not implemented.');
  89. }
  90. }