mirror of
https://github.com/docmost/docmost.git
synced 2026-08-30 02:25:01 +08:00
wrap search results in items array for API consistency
This commit is contained in:
@@ -10,8 +10,8 @@ import {
|
|||||||
export async function searchPage(
|
export async function searchPage(
|
||||||
params: IPageSearchParams,
|
params: IPageSearchParams,
|
||||||
): Promise<IPageSearch[]> {
|
): Promise<IPageSearch[]> {
|
||||||
const req = await api.post<IPageSearch[]>("/search", params);
|
const req = await api.post<{ items: IPageSearch[] }>("/search", params);
|
||||||
return req.data;
|
return req.data.items;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function searchSuggestions(
|
export async function searchSuggestions(
|
||||||
@@ -24,13 +24,13 @@ export async function searchSuggestions(
|
|||||||
export async function searchShare(
|
export async function searchShare(
|
||||||
params: IPageSearchParams,
|
params: IPageSearchParams,
|
||||||
): Promise<IPageSearch[]> {
|
): Promise<IPageSearch[]> {
|
||||||
const req = await api.post<IPageSearch[]>("/search/share-search", params);
|
const req = await api.post<{ items: IPageSearch[] }>("/search/share-search", params);
|
||||||
return req.data;
|
return req.data.items;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function searchAttachments(
|
export async function searchAttachments(
|
||||||
params: IPageSearchParams,
|
params: IPageSearchParams,
|
||||||
): Promise<IAttachmentSearch[]> {
|
): Promise<IAttachmentSearch[]> {
|
||||||
const req = await api.post<IAttachmentSearch[]>("/search-attachments", params);
|
const req = await api.post<{ items: IAttachmentSearch[] }>("/search-attachments", params);
|
||||||
return req.data;
|
return req.data.items;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ export class SearchService {
|
|||||||
userId?: string;
|
userId?: string;
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
},
|
},
|
||||||
): Promise<SearchResponseDto[]> {
|
): Promise<{ items: SearchResponseDto[] }> {
|
||||||
const { query } = searchParams;
|
const { query } = searchParams;
|
||||||
|
|
||||||
if (query.length < 1) {
|
if (query.length < 1) {
|
||||||
return;
|
return { items: [] };
|
||||||
}
|
}
|
||||||
const searchQuery = tsquery(query.trim() + '*');
|
const searchQuery = tsquery(query.trim() + '*');
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ export class SearchService {
|
|||||||
)
|
)
|
||||||
.where('deletedAt', 'is', null)
|
.where('deletedAt', 'is', null)
|
||||||
.orderBy('rank', 'desc')
|
.orderBy('rank', 'desc')
|
||||||
.limit(searchParams.limit | 25)
|
.limit(searchParams.limit || 25)
|
||||||
.offset(searchParams.offset || 0);
|
.offset(searchParams.offset || 0);
|
||||||
|
|
||||||
if (!searchParams.shareId) {
|
if (!searchParams.shareId) {
|
||||||
@@ -86,7 +86,7 @@ export class SearchService {
|
|||||||
const shareId = searchParams.shareId;
|
const shareId = searchParams.shareId;
|
||||||
const share = await this.shareRepo.findById(shareId);
|
const share = await this.shareRepo.findById(shareId);
|
||||||
if (!share || share.workspaceId !== opts.workspaceId) {
|
if (!share || share.workspaceId !== opts.workspaceId) {
|
||||||
return [];
|
return { items: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
const pageIdsToSearch = [];
|
const pageIdsToSearch = [];
|
||||||
@@ -108,10 +108,10 @@ export class SearchService {
|
|||||||
.where('id', 'in', pageIdsToSearch)
|
.where('id', 'in', pageIdsToSearch)
|
||||||
.where('workspaceId', '=', opts.workspaceId);
|
.where('workspaceId', '=', opts.workspaceId);
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return { items: [] };
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return { items: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
@@ -127,7 +127,7 @@ export class SearchService {
|
|||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
return searchResults;
|
return { items: searchResults };
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchSuggestions(
|
async searchSuggestions(
|
||||||
|
|||||||
+1
-1
Submodule apps/server/src/ee updated: 9888832270...b363767b69
Reference in New Issue
Block a user