cirelation.controller.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/core';
  2. import { CirelationService } from '../../service/users/cirelation.service';
  3. import { CVO_cirelation, FVO_cirelation, QVO_cirelation, UVAO_cirelation } from '../../interface/users/cirelation.interface';
  4. import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
  5. import { Validate } from '@midwayjs/validate';
  6. import { BaseController } from '../../frame/BaseController';
  7. import { omit, pick } from 'lodash';
  8. import { ErrorCode, ServiceError } from '../../error/service.error';
  9. import { ServiceUtilService } from '../../service/serviceUtil.service';
  10. const namePrefix = '企业孵化器关联';
  11. @ApiTags(['企业孵化器关联'])
  12. @Controller('/cirelation', { tagName: namePrefix })
  13. export class cirelationController implements BaseController {
  14. @Inject()
  15. service: CirelationService;
  16. @Inject()
  17. serviceUtil: ServiceUtilService;
  18. @Get('/')
  19. @ApiTags('列表查询')
  20. @ApiQuery({ name: 'query' })
  21. @ApiResponse({ type: QVO_cirelation })
  22. async index(@Query() query: object) {
  23. const qobj = omit(query, ['skip', 'limit']);
  24. const others = pick(query, ['skip', 'limit']);
  25. const result = await this.service.query(qobj, others);
  26. return result;
  27. }
  28. @Get('/list')
  29. async list(@Query() query: object) {
  30. const qobj = omit(query, ['skip', 'limit']);
  31. const others = pick(query, ['skip', 'limit']);
  32. const { data, total } = await this.service.query(qobj, others);
  33. const list = [];
  34. for (const i of data) {
  35. list.push(await this.service.fillName(i));
  36. }
  37. return { data: list, total };
  38. }
  39. @Get('/:id')
  40. @ApiTags('单查询')
  41. @ApiResponse({ type: FVO_cirelation })
  42. async fetch(@Param('id') id: number) {
  43. const data = await this.service.fetch({ id });
  44. const result = new FVO_cirelation(data);
  45. return result;
  46. }
  47. @Post('/', { routerName: `创建${namePrefix}` })
  48. @ApiTags('创建数据')
  49. @Validate()
  50. @ApiResponse({ type: CVO_cirelation })
  51. async create(@Body() data: object) {
  52. await this.service.createExamine(data);
  53. const dbData = await this.service.create(data);
  54. const result = new CVO_cirelation(dbData);
  55. return result;
  56. }
  57. @Post('/:id', { routerName: `修改${namePrefix}` })
  58. @ApiTags('修改数据')
  59. @Validate()
  60. @ApiResponse({ type: UVAO_cirelation })
  61. async update(@Param('id') id: number, @Body() data: object) {
  62. if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
  63. const result = await this.service.update({ id }, data);
  64. this.serviceUtil.fillIdentity(data, 'cirelation');
  65. return result;
  66. }
  67. @Del('/:id', { routerName: `删除${namePrefix}` })
  68. @ApiTags('删除数据')
  69. @Validate()
  70. async delete(@Param('id') id: number) {
  71. if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
  72. const result = await this.service.delete({ id });
  73. return result;
  74. }
  75. }