From bc77291dac8ddc8144d9d8028a66b664eae8e3bd Mon Sep 17 00:00:00 2001 From: Mamalizz Date: Sat, 22 Mar 2025 16:20:21 +0330 Subject: [PATCH] added use subscribe --- .../notifications/useSubscribeNotification.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 frontend/composables/api/notifications/useSubscribeNotification.ts diff --git a/frontend/composables/api/notifications/useSubscribeNotification.ts b/frontend/composables/api/notifications/useSubscribeNotification.ts new file mode 100644 index 0000000..17a2db9 --- /dev/null +++ b/frontend/composables/api/notifications/useSubscribeNotification.ts @@ -0,0 +1,34 @@ +// imports + +import { useMutation } from "@tanstack/vue-query"; +import { API_ENDPOINTS } from "~/constants"; + +// types + +export type SubscribeNotificationRequest = { + body: PushSubscriptionJSON; +}; + +const useSubscribeNotification = () => { + // state + + const { $axios: axios } = useNuxtApp(); + + // methods + + const handleSubscribeNotification = async ( + params: SubscribeNotificationRequest + ) => { + const { data } = await axios.post(API_ENDPOINTS.account.subscribe, { + ...params.body, + }); + return data; + }; + + return useMutation({ + mutationFn: (subscribeData: SubscribeNotificationRequest) => + handleSubscribeNotification(subscribeData), + }); +}; + +export default useSubscribeNotification;