menus.controller.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
  2. import { BaseController } from 'free-midway-component';
  3. import { MenusService } from '../service/menus.service';
  4. import { CDTO_menus, CVO_menus, FVO_menus, QDTO_menus, QVO_menus, UDTO_menus, UVAO_menus } from '../interface/menus.interface';
  5. import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
  6. import { Validate } from '@midwayjs/validate';
  7. @ApiTags(['菜单'])
  8. @Controller('/menus')
  9. export class MenusController extends BaseController {
  10. @Inject()
  11. service: MenusService;
  12. @Post('/')
  13. @Validate()
  14. @ApiResponse({ type: CVO_menus })
  15. async create(@Body() data: CDTO_menus) {
  16. const dbData = await this.service.create(data);
  17. const result = new CVO_menus(dbData);
  18. return result;
  19. }
  20. @Get('/')
  21. @ApiQuery({ name: 'query' })
  22. @ApiResponse({ type: QVO_menus })
  23. async query() {
  24. const data = await this.service.queryMenu();
  25. return data;
  26. }
  27. @Get('/:id')
  28. @ApiResponse({ type: FVO_menus })
  29. async fetch(@Param('id') id: string) {
  30. const data = await this.service.fetch(id);
  31. const result = new FVO_menus(data);
  32. return result;
  33. }
  34. @Post('/:id')
  35. @Validate()
  36. @ApiResponse({ type: UVAO_menus })
  37. async update(@Param('id') id: string, @Body() body: UDTO_menus) {
  38. const result = await this.service.updateOne(id, body);
  39. return result;
  40. }
  41. @Del('/:id')
  42. @Validate()
  43. async delete(@Param('id') id: string) {
  44. await this.service.delete(id);
  45. return 'ok';
  46. }
  47. async createMany(...args: any[]) {
  48. throw new Error('Method not implemented.');
  49. }
  50. async updateMany(...args: any[]) {
  51. throw new Error('Method not implemented.');
  52. }
  53. async deleteMany(...args: any[]) {
  54. throw new Error('Method not implemented.');
  55. }
  56. }