mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-18 08:02:03 +03:00
68642afbb8
* feat: add chat api * refactor(MicButton): move related hook * feat: add nock http call example * test(useChatApi): add unit tests
32 lines
703 B
TypeScript
32 lines
703 B
TypeScript
import { AxiosInstance } from "axios";
|
|
|
|
import { ChatEntity } from "@/app/chat/[chatId]/types";
|
|
|
|
export const createChat = async (
|
|
name: string,
|
|
axiosInstance: AxiosInstance
|
|
): Promise<ChatEntity> => {
|
|
const createdChat = (
|
|
await axiosInstance.post<ChatEntity>("/chat", { name: name })
|
|
).data;
|
|
|
|
return createdChat;
|
|
};
|
|
|
|
export const getChats = async (
|
|
axiosInstance: AxiosInstance
|
|
): Promise<ChatEntity[]> => {
|
|
const response = await axiosInstance.get<{
|
|
chats: ChatEntity[];
|
|
}>(`/chat`);
|
|
|
|
return response.data.chats;
|
|
};
|
|
|
|
export const deleteChat = async (
|
|
chatId: string,
|
|
axiosInstance: AxiosInstance
|
|
): Promise<void> => {
|
|
await axiosInstance.delete(`/chat/${chatId}`);
|
|
};
|