investment.controller.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
  2. import { BaseController } from 'free-midway-component';
  3. import { InvestmentService } from '../../service/users/investment.service';
  4. import { CDTO_investment, CVO_investment, FVO_investment, QDTO_investment, QVO_investment, UDTO_investment, UVAO_investment } from '../../interface/users/investment.interface';
  5. import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
  6. import { Validate } from '@midwayjs/validate';
  7. import { UtilService } from '../../service/util.service';
  8. @ApiTags(['投资人'])
  9. @Controller('/investment')
  10. export class InvestmentController extends BaseController {
  11. @Inject()
  12. service: InvestmentService;
  13. @Inject()
  14. utilService: UtilService;
  15. @Post('/')
  16. @Validate()
  17. @ApiResponse({ type: CVO_investment })
  18. async create(@Body() data: CDTO_investment) {
  19. const dbData = await this.service.create(data);
  20. const result = new CVO_investment(dbData);
  21. return result;
  22. }
  23. @Get('/')
  24. @ApiQuery({ name: 'query' })
  25. @ApiResponse({ type: QVO_investment })
  26. async query(@Query() filter: QDTO_investment, @Query('skip') skip: number, @Query('limit') limit: number) {
  27. const list = await this.service.query(filter, { skip, limit });
  28. const data = [];
  29. for (const i of list) {
  30. const newData = new QVO_investment(i);
  31. data.push(newData);
  32. }
  33. const total = await this.service.count(filter);
  34. return { data, total };
  35. }
  36. @Get('/:id')
  37. @ApiResponse({ type: FVO_investment })
  38. async fetch(@Param('id') id: string) {
  39. const data = await this.service.fetch(id);
  40. const result = new FVO_investment(data);
  41. return result;
  42. }
  43. @Post('/:id')
  44. @Validate()
  45. @ApiResponse({ type: UVAO_investment })
  46. async update(@Param('id') id: string, @Body() body: UDTO_investment) {
  47. const result = await this.service.updateOne(id, body);
  48. await this.utilService.updateUserAfter(id, body, 'Investment');
  49. return result;
  50. }
  51. @Del('/:id')
  52. @Validate()
  53. async delete(@Param('id') id: string) {
  54. await this.service.delete(id);
  55. return 'ok';
  56. }
  57. async createMany(...args: any[]) {
  58. throw new Error('Method not implemented.');
  59. }
  60. async updateMany(...args: any[]) {
  61. throw new Error('Method not implemented.');
  62. }
  63. async deleteMany(...args: any[]) {
  64. throw new Error('Method not implemented.');
  65. }
  66. }