journal.controller.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { JournalService } from '../../service/platform/journal.service';
  2. import { CVO_journal, FVO_journal, QVO_journal, UVAO_journal } from '../../interface/platform/journal.interface';
  3. import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
  4. import { Validate } from '@midwayjs/validate';
  5. import { Controller, Inject, Get, Param, Post, Body, Del, Query } from '@midwayjs/core';
  6. import { omit, pick } from 'lodash';
  7. import { ServiceError, ErrorCode } from '../../error/service.error';
  8. import { BaseController } from '../../frame/BaseController';
  9. const namePrefix = '行研产研';
  10. @ApiTags(['行研产研'])
  11. @Controller('/journal', { tagName: namePrefix })
  12. export class JournalController implements BaseController {
  13. @Inject()
  14. service: JournalService;
  15. @Get('/')
  16. @ApiTags('列表查询')
  17. @ApiQuery({ name: 'query' })
  18. @ApiResponse({ type: QVO_journal })
  19. async index(@Query() query: object) {
  20. const qobj = omit(query, ['skip', 'limit']);
  21. const others: any = pick(query, ['skip', 'limit']);
  22. others.order = { sort: 'ASC' };
  23. const result = await this.service.query(qobj, others);
  24. return result;
  25. }
  26. @Get('/:id')
  27. @ApiTags('单查询')
  28. @ApiResponse({ type: FVO_journal })
  29. async fetch(@Param('id') id: number) {
  30. const data = await this.service.fetch({ id });
  31. const result = new FVO_journal(data);
  32. return result;
  33. }
  34. @Post('/', { routerName: `创建${namePrefix}` })
  35. @ApiTags('创建数据')
  36. @Validate()
  37. @ApiResponse({ type: CVO_journal })
  38. async create(@Body() data: object) {
  39. const dbData = await this.service.create(data);
  40. const result = new CVO_journal(dbData);
  41. return result;
  42. }
  43. @Post('/:id', { routerName: `修改${namePrefix}` })
  44. @ApiTags('修改数据')
  45. @Validate()
  46. @ApiResponse({ type: UVAO_journal })
  47. async update(@Param('id') id: number, @Body() data: object) {
  48. if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
  49. const result = await this.service.update({ id }, data);
  50. return result;
  51. }
  52. @Del('/:id', { routerName: `删除${namePrefix}` })
  53. @ApiTags('删除数据')
  54. @Validate()
  55. async delete(@Param('id') id: number) {
  56. if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
  57. const result = await this.service.delete({ id });
  58. return result;
  59. }
  60. }