From 817cdc056713be8458f6c1c70f0f1bfd82f1c3ea Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Wed, 30 Oct 2024 11:45:54 +0700 Subject: [PATCH] feat: add notifcation store --- src/stores/notification/index.ts | 56 ++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/stores/notification/index.ts diff --git a/src/stores/notification/index.ts b/src/stores/notification/index.ts new file mode 100644 index 00000000..1243de88 --- /dev/null +++ b/src/stores/notification/index.ts @@ -0,0 +1,56 @@ +import { defineStore } from 'pinia'; +import { api } from 'src/boot/axios'; + +import { PaginationResult } from 'src/types'; +import { createDataRefBase } from '../utils'; + +export type Notification = {}; + +export const useNotification = defineStore('noti-store', () => { + const state = createDataRefBase(); + + async function getNotification(id: string) { + const res = await api.get(`/notification/${id}`); + if (res.status >= 400) return null; + return res.data; + } + + async function getNotificationList(params?: { + page?: number; + pageSize?: number; + query?: string; + quotationId?: string; + }) { + const res = await api.get>('/notification', { + params, + }); + if (res.status >= 400) return null; + return res.data; + } + + async function updateNotification(paymentId: string, payload: Notification) { + const res = await api.put( + `/notification/${paymentId}`, + payload, + ); + if (res.status >= 400) return null; + return res.data; + } + + async function deleteNotification(notificationId: string) { + const res = await api.delete( + `/notification/${notificationId}`, + ); + if (res.status >= 400) return null; + return res.data; + } + + return { + ...state, + + getNotification, + getNotificationList, + updateNotification, + deleteNotification, + }; +});