schema.controller.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import {
  2. Body,
  3. Controller,
  4. Get,
  5. Post,
  6. Query,
  7. UsePipes,
  8. ValidationPipe,
  9. } from '@nestjs/common';
  10. import { ApiTags } from '@nestjs/swagger';
  11. import {
  12. DescribeIndex,
  13. GetIndexProgress,
  14. ManageIndex,
  15. ManageType,
  16. GetIndexState,
  17. } from './dto';
  18. import { SchemaService } from './schema.service';
  19. @ApiTags('schema')
  20. @Controller('schema')
  21. export class SchemaController {
  22. constructor(private schemaService: SchemaService) { }
  23. @Post('index')
  24. @UsePipes(new ValidationPipe())
  25. async manageIndex(@Body() body: ManageIndex) {
  26. const { type, collection_name, extra_params, field_name } = body;
  27. return type === ManageType.CREATE
  28. ? await this.schemaService.createIndex({
  29. collection_name,
  30. extra_params,
  31. field_name,
  32. })
  33. : await this.schemaService.dropIndex({ collection_name, field_name });
  34. }
  35. @Get('index')
  36. @UsePipes(new ValidationPipe())
  37. async describeIndex(@Query() query: DescribeIndex) {
  38. return await this.schemaService.describeIndex(query);
  39. }
  40. @Get('index/progress')
  41. @UsePipes(new ValidationPipe())
  42. async getIndexProgress(@Query() query: GetIndexProgress) {
  43. return await this.schemaService.getIndexBuildProgress(query);
  44. }
  45. @Get('index/state')
  46. @UsePipes(new ValidationPipe())
  47. async getIndexState(@Query() query: GetIndexState) {
  48. return await this.schemaService.getIndexState(query);
  49. }
  50. }