From 587733e6f9ecf162b2e7f38bba433b48f51a7df3 Mon Sep 17 00:00:00 2001 From: matthieu Date: Sun, 15 Mar 2026 19:47:21 +0100 Subject: [PATCH] feat(frontend) : add notification DTO and service --- frontend/services/dto/notification.ts | 13 +++++++++++ frontend/services/notifications.ts | 33 +++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 frontend/services/dto/notification.ts create mode 100644 frontend/services/notifications.ts diff --git a/frontend/services/dto/notification.ts b/frontend/services/dto/notification.ts new file mode 100644 index 0000000..4c8e293 --- /dev/null +++ b/frontend/services/dto/notification.ts @@ -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 +} diff --git a/frontend/services/notifications.ts b/frontend/services/notifications.ts new file mode 100644 index 0000000..1417259 --- /dev/null +++ b/frontend/services/notifications.ts @@ -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 { + const data = await api.get>('/notifications') + return extractHydraMembers(data) + } + + async function markAsRead(id: number): Promise { + await api.patch(`/notifications/${id}`, { isRead: true }, { + toast: false, + }) + } + + async function markAllAsRead(): Promise { + await api.post('/notifications/mark-all-read', {}, { + toast: false, + }) + } + + async function getUnreadCount(): Promise { + const data = await api.get<{ count: number }>('/notifications/unread-count', {}, { + toast: false, + }) + return data.count + } + + return { getAll, markAsRead, markAllAsRead, getUnreadCount } +}