feat: add notifcation store

This commit is contained in:
Methapon Metanipat 2024-10-30 11:45:54 +07:00
parent 77bc4973a9
commit 817cdc0567

View file

@ -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<Notification>();
async function getNotification(id: string) {
const res = await api.get<Notification>(`/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<PaginationResult<Notification>>('/notification', {
params,
});
if (res.status >= 400) return null;
return res.data;
}
async function updateNotification(paymentId: string, payload: Notification) {
const res = await api.put<Notification & { id: string }>(
`/notification/${paymentId}`,
payload,
);
if (res.status >= 400) return null;
return res.data;
}
async function deleteNotification(notificationId: string) {
const res = await api.delete<Notification & { id: string }>(
`/notification/${notificationId}`,
);
if (res.status >= 400) return null;
return res.data;
}
return {
...state,
getNotification,
getNotificationList,
updateNotification,
deleteNotification,
};
});