investment.controller.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/core';
  2. import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
  3. import { Validate } from '@midwayjs/validate';
  4. import { BaseController } from '../../frame/BaseController';
  5. import { omit, pick } from 'lodash';
  6. import { ErrorCode, ServiceError } from '../../error/service.error';
  7. import { Context } from '@midwayjs/koa';
  8. import { InvestmentService } from '../../service/users/investment.service';
  9. import { QVO_investment, FVO_investment, CVO_investment, UVAO_investment } from '../../interface/users/investment.interface';
  10. import { ServiceUtilService } from '../../service/serviceUtil.service';
  11. const namePrefix = '投资人';
  12. @ApiTags(['投资人'])
  13. @Controller('/investment', { tagName: namePrefix })
  14. export class InvestmentController implements BaseController {
  15. @Inject()
  16. service: InvestmentService;
  17. @Inject()
  18. ctx: Context;
  19. @Inject()
  20. serviceUtil: ServiceUtilService;
  21. @Post('/examine', { routerName: `审核${namePrefix}` })
  22. @ApiTags('信息审核')
  23. @ApiQuery({ name: 'examine' })
  24. async examine(@Body('id') id: number, @Body('status') status: string) {
  25. if (!id || !status) throw new ServiceError(ErrorCode.BODY_ERROR);
  26. const result = await this.service.update({ id }, { status });
  27. return result;
  28. }
  29. @Get('/')
  30. @ApiTags('列表查询')
  31. @ApiQuery({ name: 'query' })
  32. @ApiResponse({ type: QVO_investment })
  33. async index(@Query() query: object) {
  34. const qobj = omit(query, ['skip', 'limit']);
  35. const others = pick(query, ['skip', 'limit']);
  36. const result = await this.service.query(qobj, others);
  37. return result;
  38. }
  39. @Get('/:id')
  40. @ApiTags('单查询')
  41. @ApiResponse({ type: FVO_investment })
  42. async fetch(@Param('id') id: number) {
  43. const data = await this.service.fetch({ id });
  44. const result = new FVO_investment(data);
  45. return result;
  46. }
  47. @Post('/', { routerName: `创建${namePrefix}` })
  48. @ApiTags('创建数据')
  49. @Validate()
  50. @ApiResponse({ type: CVO_investment })
  51. async create(@Body() data: object) {
  52. const dbData = await this.service.create(data);
  53. this.serviceUtil.fillIdentity(data, 'Investment');
  54. const result = new CVO_investment(dbData);
  55. return result;
  56. }
  57. @Post('/:id', { routerName: `修改${namePrefix}` })
  58. @ApiTags('修改数据')
  59. @Validate()
  60. @ApiResponse({ type: UVAO_investment })
  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, 'Investment');
  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. }