patent.controller.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 { PatentService } from '../service/patent.service';
  13. import {
  14. CDTO_patent,
  15. CVO_patent,
  16. FVO_patent,
  17. QDTO_patent,
  18. QVO_patent,
  19. UDTO_patent,
  20. UVAO_patent,
  21. ImportDTO,
  22. } from '../interface/patent.interface';
  23. import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
  24. import { Validate } from '@midwayjs/validate';
  25. @ApiTags(['e专利'])
  26. @Controller('/patent')
  27. export class PatentController extends BaseController {
  28. @Inject()
  29. service: PatentService;
  30. @Post('/')
  31. @Validate()
  32. @ApiResponse({ type: CVO_patent })
  33. async create(@Body() data: CDTO_patent) {
  34. const dbData = await this.service.create(data);
  35. const result = new CVO_patent(dbData);
  36. return result;
  37. }
  38. @Get('/')
  39. @ApiQuery({ name: 'query' })
  40. @ApiResponse({ type: QVO_patent })
  41. async query(
  42. @Query() filter: QDTO_patent,
  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_patent(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_patent })
  57. async fetch(@Param('id') id: string) {
  58. const data = await this.service.fetch(id);
  59. const result = new FVO_patent(data);
  60. return result;
  61. }
  62. @Post('/:id')
  63. @Validate()
  64. @ApiResponse({ type: UVAO_patent })
  65. async update(@Param('id') id: string, @Body() body: UDTO_patent) {
  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. @Post('/export')
  82. @Validate()
  83. async export(@Body() body: any) {
  84. const result = await this.service.export(body);
  85. return result;
  86. }
  87. async createMany(...args: any[]) {
  88. throw new Error('Method not implemented.');
  89. }
  90. async updateMany(...args: any[]) {
  91. throw new Error('Method not implemented.');
  92. }
  93. async deleteMany(...args: any[]) {
  94. throw new Error('Method not implemented.');
  95. }
  96. }