add delete conversation mutation, fix withAuthentication on post requests

This commit is contained in:
Daniel D Orlando 2023-04-03 12:39:00 -07:00
parent bd53b878d4
commit 94e0636b32
5 changed files with 68 additions and 49 deletions

View file

@ -8,7 +8,6 @@ import {
} from "@tanstack/react-query";
import * as t from "./types";
import * as dataService from "./data-service";
import store from '~/store';
export enum QueryKeys {
messages = "messsages",
@ -74,16 +73,27 @@ export const useUpdateConversationMutation = (
{
onSuccess: () => {
queryClient.invalidateQueries([QueryKeys.conversation, id]);
queryClient.invalidateQueries([QueryKeys.allConversations, id]);
queryClient.invalidateQueries([QueryKeys.allConversations]);
},
}
);
};
// export const useDeleteConversationMutation = (
// id: string
// ): UseMutationResult<
export const useDeleteConversationMutation = (
id: string
): UseMutationResult<t.TDeleteConversationResponse, unknown, t.TDeleteConversationRequest, unknown> => {
const queryClient = useQueryClient();
return useMutation(
(payload: t.TDeleteConversationRequest) =>
dataService.deleteConversation(payload),
{
onSuccess: () => {
queryClient.invalidateQueries([QueryKeys.conversation, id]);
queryClient.invalidateQueries([QueryKeys.allConversations]);
},
}
);
};
export const useUpdateCustomGptMutation = (): UseMutationResult<
t.TUpdateCustomGptResponse,

View file

@ -1,13 +1,13 @@
import axios, { AxiosRequestConfig } from "axios";
async function _get<T>(url: string, options?: AxiosRequestConfig): Promise<T> {
const response = await axios.get(url, { withCredentials: true, ...options});
const response = await axios.get(url, {...options});
return response.data;
}
async function _post(url: string, data?: any) {
const response = await axios.post(url, JSON.stringify(data), {
withCredentials: true,
async function _post(url: string, arg?: any) {
const modifiedData = {arg, withCredentials: true}
const response = await axios.post(url, modifiedData, {
headers: { "Content-Type": "application/json" },
});
return response.data;
@ -19,7 +19,6 @@ async function _postMultiPart(
options?: AxiosRequestConfig
) {
const response = await axios.post(url, formData, {
withCredentials: true,
...options,
headers: { "Content-Type": "multipart/form-data" },
});
@ -28,14 +27,13 @@ async function _postMultiPart(
async function _put(url: string, data?: any) {
const response = await axios.put(url, JSON.stringify(data), {
withCredentials: true,
headers: { "Content-Type": "application/json" },
});
return response.data;
}
async function _delete<T>(url: string): Promise<T> {
const response = await axios.delete(url, { withCredentials: true });
const response = await axios.delete(url);
return response.data;
}
@ -43,13 +41,12 @@ async function _deleteWithOptions<T>(
url: string,
options?: AxiosRequestConfig
): Promise<T> {
const response = await axios.delete(url, { withCredentials: true, ...options});
const response = await axios.delete(url, {...options});
return response.data;
}
async function _patch(url: string, data?: any) {
const response = await axios.patch(url, JSON.stringify(data), {
withCredentials: true,
headers: { "Content-Type": "application/json" },
});
return response.data;

View file

@ -106,10 +106,6 @@ export type TGetMessagesResponse = {
data: TMessage[]
};
export type TDeleteConversationRequest = {
conversationId: string
};
export type TAICompletionRequest = {
chatGptLabel?: string,
conversationId: string,
@ -150,8 +146,10 @@ export type TConversationUpdate = {
conversationId: string,
title?: string
};
export type TUpdateConversationRequest = {
arg: {},
conversationId: string,
title: string,
withCredentials?: boolean
};
@ -159,6 +157,20 @@ export type TUpdateConversationResponse = {
data: TConversation
};
export type TDeleteConversationRequest = {
conversationId: string,
source: string
}
export type TDeleteConversationResponse = {
acknowledged: boolean,
deletedCount: number,
messages: {
acknowledged: boolean,
deletedCount: number
}
};
export type TUpdateCustomGptRequest = {
value: string,
chatGptLabel: string,