2
0

schema.controller.ts 1.3 KB

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