config.controller.ts 2.2 KB

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