expert.controller.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
  2. import { BaseController } from 'free-midway-component';
  3. import { ExpertService } from '../../service/users/expert.service';
  4. import { CDTO_expert, CVO_expert, FVO_expert, QDTO_expert, QVO_expert, UDTO_expert, UVAO_expert } from '../../interface/users/expert.interface';
  5. import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
  6. import { Validate } from '@midwayjs/validate';
  7. @ApiTags(['专家'])
  8. @Controller('/expert')
  9. export class ExpertController extends BaseController {
  10. @Inject()
  11. service: ExpertService;
  12. @Post('/')
  13. @Validate()
  14. @ApiResponse({ type: CVO_expert })
  15. async create(@Body() data: CDTO_expert) {
  16. const dbData = await this.service.create(data);
  17. const result = new CVO_expert(dbData);
  18. return result;
  19. }
  20. @Get('/')
  21. @ApiQuery({ name: 'query' })
  22. @ApiResponse({ type: QVO_expert })
  23. async query(@Query() filter: QDTO_expert, @Query('skip') skip: number, @Query('limit') limit: number) {
  24. const list = await this.service.query(filter, { skip, limit });
  25. const data = [];
  26. for (const i of list) {
  27. const newData = new QVO_expert(i);
  28. data.push(newData);
  29. }
  30. const total = await this.service.count(filter);
  31. return { data, total };
  32. }
  33. @Get('/:id')
  34. @ApiResponse({ type: FVO_expert })
  35. async fetch(@Param('id') id: string) {
  36. const data = await this.service.fetch(id);
  37. const result = new FVO_expert(data);
  38. return result;
  39. }
  40. @Post('/:id')
  41. @Validate()
  42. @ApiResponse({ type: UVAO_expert })
  43. async update(@Param('id') id: string, @Body() body: UDTO_expert) {
  44. const result = await this.service.updateOne(id, body);
  45. return result;
  46. }
  47. @Del('/:id')
  48. @Validate()
  49. async delete(@Param('id') id: string) {
  50. await this.service.delete(id);
  51. return 'ok';
  52. }
  53. async createMany(...args: any[]) {
  54. throw new Error('Method not implemented.');
  55. }
  56. async updateMany(...args: any[]) {
  57. throw new Error('Method not implemented.');
  58. }
  59. async deleteMany(...args: any[]) {
  60. throw new Error('Method not implemented.');
  61. }
  62. }