Merge pull request #188 from Frappet/feat/notification
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 7s

feat: notification
This commit is contained in:
Methapon Metanipat 2025-03-06 13:51:58 +07:00 committed by GitHub
commit cd231513ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 457 additions and 61 deletions

View file

@ -4,7 +4,13 @@ import { api } from 'src/boot/axios';
import { PaginationResult } from 'src/types';
import { createDataRefBase } from '../utils';
export type Notification = {};
export type Notification = {
id: string;
title: string;
detail: string;
read?: boolean;
createdAt: string;
};
export const useNotification = defineStore('noti-store', () => {
const state = createDataRefBase<Notification>();
@ -28,9 +34,12 @@ export const useNotification = defineStore('noti-store', () => {
return res.data;
}
async function updateNotification(paymentId: string, payload: Notification) {
async function updateNotification(
notificationId: string,
payload: Notification,
) {
const res = await api.put<Notification & { id: string }>(
`/notification/${paymentId}`,
`/notification/${notificationId}`,
payload,
);
if (res.status >= 400) return null;
@ -45,6 +54,26 @@ export const useNotification = defineStore('noti-store', () => {
return res.data;
}
async function deleteMultiNotification(notificationId: string[]) {
const res = await api.delete<Notification & { id: string }>(
'/notification',
{
data: notificationId,
},
);
if (res.status >= 400) return null;
return true;
}
async function markReadNotification(notificationId: string[]) {
const res = await api.post<Notification & { id: string }>(
'/notification/mark-read',
{ id: notificationId },
);
if (res.status >= 400) return null;
return true;
}
return {
...state,
@ -52,5 +81,7 @@ export const useNotification = defineStore('noti-store', () => {
getNotificationList,
updateNotification,
deleteNotification,
deleteMultiNotification,
markReadNotification,
};
});

View file

@ -532,7 +532,7 @@ export function createDataRefBase<T>(
defaultPageSize = 30,
) {
return {
data: ref<T[]>(),
data: ref<T[]>([]),
page: ref<number>(defaultPage),
pageMax: ref<number>(defaultPageMax),
pageSize: ref<number>(defaultPageSize),