mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-26 17:26:23 +02:00
feat: add server side chat search functionality
- Implemented a new endpoint for searching chats by title substring in the backend. - Updated the frontend to support chat searching with a debounced input. - Added validation for pagination parameters and search space ID. - Enhanced API service to handle search requests and return results based on user permissions.
This commit is contained in:
parent
48ea41a8d2
commit
70ca585379
4 changed files with 165 additions and 24 deletions
|
|
@ -11,6 +11,8 @@ import {
|
|||
type GetChatsRequest,
|
||||
getChatDetailsRequest,
|
||||
getChatsRequest,
|
||||
type SearchChatsRequest,
|
||||
searchChatsRequest,
|
||||
type UpdateChatRequest,
|
||||
updateChatRequest,
|
||||
} from "@/contracts/types/chat.types";
|
||||
|
|
@ -59,6 +61,28 @@ class ChatApiService {
|
|||
return baseApiService.get(`/api/v1/chats?${queryParams}`, z.array(chatSummary));
|
||||
};
|
||||
|
||||
searchChats = async (request: SearchChatsRequest) => {
|
||||
// Validate the request
|
||||
const parsedRequest = searchChatsRequest.safeParse(request);
|
||||
|
||||
if (!parsedRequest.success) {
|
||||
console.error("Invalid request:", parsedRequest.error);
|
||||
|
||||
// Format a user frendly error message
|
||||
const errorMessage = parsedRequest.error.errors.map((err) => err.message).join(", ");
|
||||
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
||||
}
|
||||
|
||||
// Transform queries params to be string values
|
||||
const transformedQueryParams = Object.fromEntries(
|
||||
Object.entries(parsedRequest.data.queryParams).map(([k, v]) => [k, String(v)])
|
||||
);
|
||||
|
||||
const queryParams = new URLSearchParams(transformedQueryParams).toString();
|
||||
|
||||
return baseApiService.get(`/api/v1/chats/search?${queryParams}`, z.array(chatSummary));
|
||||
};
|
||||
|
||||
deleteChat = async (request: DeleteChatRequest) => {
|
||||
// Validate the request
|
||||
const parsedRequest = deleteChatRequest.safeParse(request);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue