Merge pull request #188 from Frappet/feat/notification
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 7s
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 7s
feat: notification
This commit is contained in:
commit
cd231513ee
8 changed files with 457 additions and 61 deletions
|
|
@ -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,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue