diff --git a/frontend/composables/api/account/useGetAllNotifications.ts b/frontend/composables/api/account/useGetAllNotifications.ts new file mode 100644 index 0000000..68dfa77 --- /dev/null +++ b/frontend/composables/api/account/useGetAllNotifications.ts @@ -0,0 +1,41 @@ +// imports + +import { useQuery } from "@tanstack/vue-query"; +import { API_ENDPOINTS, QUERY_KEYS } from "~/constants"; + +// types + +export type GetAllNotificationsResponse = ApiPaginated; + +export type GetAllNotificationsRequest = { + sort: string | undefined; + status: string | undefined; + page: string | string[]; +}; + +const useGetAllNotifications = (params: ComputedRef) => { + // state + + const { $axios: axios } = useNuxtApp(); + + // methods + + const handleGetAllNotifications = async (params: GetAllNotificationsRequest) => { + const { data } = await axios.get(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;