config.controller.ts 1.8 KB

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