dataLogs.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 { DataLogsService } from '../../service/record/dataLogs.service';
  4. import { CDTO_dataLogs, CVO_dataLogs, FVO_dataLogs, QDTO_dataLogs, QVO_dataLogs, UDTO_dataLogs, UVAO_dataLogs } from '../../interface/record/dataLogs.interface';
  5. import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
  6. import { Validate } from '@midwayjs/validate';
  7. @ApiTags(['mongodb oplog'])
  8. @Controller('/dataLogs')
  9. export class DataLogsController extends BaseController {
  10. @Inject()
  11. service: DataLogsService;
  12. @Post('/')
  13. @Validate()
  14. @ApiResponse({ type: CVO_dataLogs })
  15. async create(@Body() data: CDTO_dataLogs) {
  16. const dbData = await this.service.create(data);
  17. const result = new CVO_dataLogs(dbData);
  18. return result;
  19. }
  20. @Get('/')
  21. @ApiQuery({ name: 'query' })
  22. @ApiResponse({ type: QVO_dataLogs })
  23. async query(@Query() filter: QDTO_dataLogs, @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_dataLogs(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_dataLogs })
  35. async fetch(@Param('id') id: string) {
  36. const data = await this.service.fetch(id);
  37. const result = new FVO_dataLogs(data);
  38. return result;
  39. }
  40. @Post('/:id')
  41. @Validate()
  42. @ApiResponse({ type: UVAO_dataLogs })
  43. async update(@Param('id') id: string, @Body() body: UDTO_dataLogs) {
  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. }