quivr/frontend/lib/api/chat/chat.ts
Mamadou DICKO 68642afbb8
Frontend/test/chat 2 (#516)
* feat: add chat api

* refactor(MicButton): move related hook

* feat: add nock http call example

* test(useChatApi): add unit tests
2023-07-05 13:33:26 +02:00

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}`);
};