fix: address code review feedback
- Add explicit return types to all SearchController methods - Import necessary types (PaginatedSearchResults, PaginatedEntries) - Define RecentEntriesResponse interface for type safety - Ensures compliance with TypeScript strict typing standards
This commit is contained in:
@@ -1,9 +1,21 @@
|
|||||||
import { Controller, Get, Query, UseGuards } from "@nestjs/common";
|
import { Controller, Get, Query, UseGuards } from "@nestjs/common";
|
||||||
import { SearchService } from "./services/search.service";
|
import { SearchService, PaginatedSearchResults } from "./services/search.service";
|
||||||
import { SearchQueryDto, TagSearchDto, RecentEntriesDto } from "./dto";
|
import { SearchQueryDto, TagSearchDto, RecentEntriesDto } from "./dto";
|
||||||
import { AuthGuard } from "../auth/guards/auth.guard";
|
import { AuthGuard } from "../auth/guards/auth.guard";
|
||||||
import { WorkspaceGuard, PermissionGuard } from "../common/guards";
|
import { WorkspaceGuard, PermissionGuard } from "../common/guards";
|
||||||
import { Workspace, Permission, RequirePermission } from "../common/decorators";
|
import { Workspace, Permission, RequirePermission } from "../common/decorators";
|
||||||
|
import type {
|
||||||
|
PaginatedEntries,
|
||||||
|
KnowledgeEntryWithTags,
|
||||||
|
} from "./entities/knowledge-entry.entity";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Response for recent entries endpoint
|
||||||
|
*/
|
||||||
|
interface RecentEntriesResponse {
|
||||||
|
data: KnowledgeEntryWithTags[];
|
||||||
|
count: number;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for knowledge search endpoints
|
* Controller for knowledge search endpoints
|
||||||
@@ -30,7 +42,7 @@ export class SearchController {
|
|||||||
async search(
|
async search(
|
||||||
@Workspace() workspaceId: string,
|
@Workspace() workspaceId: string,
|
||||||
@Query() query: SearchQueryDto
|
@Query() query: SearchQueryDto
|
||||||
) {
|
): Promise<PaginatedSearchResults> {
|
||||||
return this.searchService.search(query.q, workspaceId, {
|
return this.searchService.search(query.q, workspaceId, {
|
||||||
status: query.status,
|
status: query.status,
|
||||||
page: query.page,
|
page: query.page,
|
||||||
@@ -53,7 +65,7 @@ export class SearchController {
|
|||||||
async searchByTags(
|
async searchByTags(
|
||||||
@Workspace() workspaceId: string,
|
@Workspace() workspaceId: string,
|
||||||
@Query() query: TagSearchDto
|
@Query() query: TagSearchDto
|
||||||
) {
|
): Promise<PaginatedEntries> {
|
||||||
return this.searchService.searchByTags(query.tags, workspaceId, {
|
return this.searchService.searchByTags(query.tags, workspaceId, {
|
||||||
status: query.status,
|
status: query.status,
|
||||||
page: query.page,
|
page: query.page,
|
||||||
@@ -74,7 +86,7 @@ export class SearchController {
|
|||||||
async recentEntries(
|
async recentEntries(
|
||||||
@Workspace() workspaceId: string,
|
@Workspace() workspaceId: string,
|
||||||
@Query() query: RecentEntriesDto
|
@Query() query: RecentEntriesDto
|
||||||
) {
|
): Promise<RecentEntriesResponse> {
|
||||||
const entries = await this.searchService.recentEntries(
|
const entries = await this.searchService.recentEntries(
|
||||||
workspaceId,
|
workspaceId,
|
||||||
query.limit || 10,
|
query.limit || 10,
|
||||||
|
|||||||
Reference in New Issue
Block a user