From 8f1391a1d899f0d801b69580505602bcf1a91b82 Mon Sep 17 00:00:00 2001 From: Mamalizz Date: Sun, 25 May 2025 00:18:36 +0330 Subject: [PATCH] added use get all notifications --- .../api/account/useGetAllNotifications.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 frontend/composables/api/account/useGetAllNotifications.ts 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;