search-history.controller.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {
  2. Controller,
  3. Get,
  4. Post,
  5. Delete,
  6. Body,
  7. Param,
  8. Query,
  9. UseGuards,
  10. Request,
  11. } from '@nestjs/common';
  12. import { CombinedAuthGuard } from '../auth/combined-auth.guard';
  13. import { SearchHistoryService } from './search-history.service';
  14. import { I18nService } from '../i18n/i18n.service';
  15. @Controller('search-history')
  16. @UseGuards(CombinedAuthGuard)
  17. export class SearchHistoryController {
  18. constructor(
  19. private readonly searchHistoryService: SearchHistoryService,
  20. private readonly i18nService: I18nService,
  21. ) { }
  22. @Get()
  23. async findAll(
  24. @Request() req,
  25. @Query('page') page: string = '1',
  26. @Query('limit') limit: string = '20',
  27. ) {
  28. const pageNum = parseInt(page, 10) || 1;
  29. const limitNum = parseInt(limit, 10) || 20;
  30. return await this.searchHistoryService.findAll(req.user.id, req.user.tenantId, pageNum, limitNum);
  31. }
  32. @Get(':id')
  33. async findOne(@Param('id') id: string, @Request() req) {
  34. return await this.searchHistoryService.findOne(id, req.user.id, req.user.tenantId);
  35. }
  36. @Post()
  37. async create(
  38. @Body() body: { title: string; selectedGroups?: string[] },
  39. @Request() req,
  40. ) {
  41. const history = await this.searchHistoryService.create(
  42. req.user.id,
  43. req.user.tenantId,
  44. body.title,
  45. body.selectedGroups,
  46. );
  47. return { id: history.id };
  48. }
  49. @Delete(':id')
  50. async remove(@Param('id') id: string, @Request() req) {
  51. await this.searchHistoryService.remove(id, req.user.id, req.user.tenantId);
  52. return { message: this.i18nService.getMessage('searchHistoryDeleted') };
  53. }
  54. }