Collection.controller.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 { CollectionService } from '../service/Collection.service';
  13. import {
  14. CDTO_Collection,
  15. CVO_Collection,
  16. FVO_Collection,
  17. QDTO_Collection,
  18. QVO_Collection,
  19. UDTO_Collection,
  20. UVAO_Collection,
  21. } from '../interface/Collection.interface';
  22. import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
  23. import { Validate } from '@midwayjs/validate';
  24. @ApiTags(['回款审批设置'])
  25. @Controller('/Collection')
  26. export class CollectionController extends BaseController {
  27. @Inject()
  28. service: CollectionService;
  29. @Post('/')
  30. @Validate()
  31. @ApiResponse({ type: CVO_Collection })
  32. async create(@Body() data: CDTO_Collection) {
  33. const dbData = await this.service.create(data);
  34. const result = new CVO_Collection(dbData);
  35. return result;
  36. }
  37. @Get('/')
  38. @ApiQuery({ name: 'query' })
  39. @ApiResponse({ type: QVO_Collection })
  40. async query(
  41. @Query() filter: QDTO_Collection,
  42. @Query('skip') skip: number,
  43. @Query('limit') limit: number
  44. ) {
  45. const list = await this.service.query(filter, { skip, limit });
  46. const data = [];
  47. for (const i of list) {
  48. const newData = new QVO_Collection(i);
  49. data.push(newData);
  50. }
  51. const total = await this.service.count(filter);
  52. return { data, total };
  53. }
  54. @Get('/:id')
  55. @ApiResponse({ type: FVO_Collection })
  56. async fetch(@Param('id') id: string) {
  57. const data = await this.service.fetch(id);
  58. const result = new FVO_Collection(data);
  59. return result;
  60. }
  61. @Post('/:id')
  62. @Validate()
  63. @ApiResponse({ type: UVAO_Collection })
  64. async update(@Param('id') id: string, @Body() body: UDTO_Collection) {
  65. const result = await this.service.updateOne(id, body);
  66. return result;
  67. }
  68. @Del('/:id')
  69. @Validate()
  70. async delete(@Param('id') id: string) {
  71. await this.service.delete(id);
  72. return 'ok';
  73. }
  74. async createMany(...args: any[]) {
  75. throw new Error('Method not implemented.');
  76. }
  77. async updateMany(...args: any[]) {
  78. throw new Error('Method not implemented.');
  79. }
  80. async deleteMany(...args: any[]) {
  81. throw new Error('Method not implemented.');
  82. }
  83. }