added use get all notifications
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
// imports
|
||||
|
||||
import { useQuery } from "@tanstack/vue-query";
|
||||
import { API_ENDPOINTS, QUERY_KEYS } from "~/constants";
|
||||
|
||||
// types
|
||||
|
||||
export type GetAllNotificationsResponse = ApiPaginated<Notification>;
|
||||
|
||||
export type GetAllNotificationsRequest = {
|
||||
sort: string | undefined;
|
||||
status: string | undefined;
|
||||
page: string | string[];
|
||||
};
|
||||
|
||||
const useGetAllNotifications = (params: ComputedRef<GetAllNotificationsRequest>) => {
|
||||
// state
|
||||
|
||||
const { $axios: axios } = useNuxtApp();
|
||||
|
||||
// methods
|
||||
|
||||
const handleGetAllNotifications = async (params: GetAllNotificationsRequest) => {
|
||||
const { data } = await axios.get<GetAllNotificationsResponse>(API_ENDPOINTS.account.notifications.get_all, {
|
||||
params: {
|
||||
sort: params.sort,
|
||||
filter: params.status,
|
||||
offset: Number(params.page) * 10 - 10,
|
||||
limit: 10,
|
||||
},
|
||||
});
|
||||
return data;
|
||||
};
|
||||
|
||||
return useQuery({
|
||||
queryKey: [QUERY_KEYS.notifications, params],
|
||||
queryFn: () => handleGetAllNotifications(params.value),
|
||||
});
|
||||
};
|
||||
|
||||
export default useGetAllNotifications;
|
||||
Reference in New Issue
Block a user