team.controller.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 { TeamService } from '../service/team.service';
  13. import {
  14. CDTO_team,
  15. CVO_team,
  16. FVO_team,
  17. QVO_team,
  18. UDTO_team,
  19. UVAO_team,
  20. } from '../interface/team.interface';
  21. import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
  22. import { Validate } from '@midwayjs/validate';
  23. @ApiTags(['团队'])
  24. @Controller('/team')
  25. export class TeamController extends BaseController {
  26. @Inject()
  27. service: TeamService;
  28. @Post('/')
  29. @Validate()
  30. @ApiResponse({ type: CVO_team })
  31. async create(@Body() data: CDTO_team) {
  32. const dbData = await this.service.create(data);
  33. const result = new CVO_team(dbData);
  34. return result;
  35. }
  36. @Get('/')
  37. @ApiQuery({ name: 'query' })
  38. @ApiResponse({ type: QVO_team })
  39. async query(@Query() filter: any) {
  40. const list = await this.service.specialQuery(filter);
  41. const data = [];
  42. for (const i of list.data) {
  43. const newData = new QVO_team(i);
  44. data.push(newData);
  45. }
  46. const total = list.total;
  47. return { data, total };
  48. }
  49. @Get('/:id')
  50. @ApiResponse({ type: FVO_team })
  51. async fetch(@Param('id') id: string) {
  52. const data = await this.service.fetch(id);
  53. const result = new FVO_team(data);
  54. return result;
  55. }
  56. @Post('/:id')
  57. @Validate()
  58. @ApiResponse({ type: UVAO_team })
  59. async update(@Param('id') id: string, @Body() body: UDTO_team) {
  60. const result = await this.service.updateOne(id, body);
  61. return result;
  62. }
  63. @Del('/:id')
  64. @Validate()
  65. async delete(@Param('id') id: string) {
  66. await this.service.delete(id);
  67. return 'ok';
  68. }
  69. async createMany(...args: any[]) {
  70. throw new Error('Method not implemented.');
  71. }
  72. async updateMany(...args: any[]) {
  73. throw new Error('Method not implemented.');
  74. }
  75. async deleteMany(...args: any[]) {
  76. throw new Error('Method not implemented.');
  77. }
  78. }