feat(frontend) : add notification DTO and service
This commit is contained in:
13
frontend/services/dto/notification.ts
Normal file
13
frontend/services/dto/notification.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export type NotificationType = 'ticket_created' | 'ticket_status_changed'
|
||||
|
||||
export type Notification = {
|
||||
'@id'?: string
|
||||
id: number
|
||||
user: string
|
||||
type: NotificationType
|
||||
title: string
|
||||
message: string
|
||||
relatedTicket: string | null
|
||||
isRead: boolean
|
||||
createdAt: string
|
||||
}
|
||||
33
frontend/services/notifications.ts
Normal file
33
frontend/services/notifications.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { Notification } from './dto/notification'
|
||||
import type { HydraCollection } from '~/utils/api'
|
||||
import { extractHydraMembers } from '~/utils/api'
|
||||
|
||||
export function useNotificationService() {
|
||||
const api = useApi()
|
||||
|
||||
async function getAll(): Promise<Notification[]> {
|
||||
const data = await api.get<HydraCollection<Notification>>('/notifications')
|
||||
return extractHydraMembers(data)
|
||||
}
|
||||
|
||||
async function markAsRead(id: number): Promise<void> {
|
||||
await api.patch(`/notifications/${id}`, { isRead: true }, {
|
||||
toast: false,
|
||||
})
|
||||
}
|
||||
|
||||
async function markAllAsRead(): Promise<void> {
|
||||
await api.post('/notifications/mark-all-read', {}, {
|
||||
toast: false,
|
||||
})
|
||||
}
|
||||
|
||||
async function getUnreadCount(): Promise<number> {
|
||||
const data = await api.get<{ count: number }>('/notifications/unread-count', {}, {
|
||||
toast: false,
|
||||
})
|
||||
return data.count
|
||||
}
|
||||
|
||||
return { getAll, markAsRead, markAllAsRead, getUnreadCount }
|
||||
}
|
||||
Reference in New Issue
Block a user