Files
Lesstime/frontend/services/notifications.ts
T
Matthieu 4d3879156d fix(pagination) : éviter la troncature silencieuse des collections paginées (LST-52)
API Platform pagine par défaut à 30 éléments/page et le helper front
extractHydraMembers ne lit que la première page (il ignore hydra:view.next),
ce qui tronque silencieusement toute liste de plus de 30 éléments.

- Back : paginationEnabled false sur les GetCollection consommées en entier
  et à volume borné/modéré (Client, Project, User, TaskTag, TaskGroup,
  TaskStatus, TaskPriority, TaskEffort, Workflow).
- Front : nouveau helper fetchAllHydra() qui parcourt toutes les pages ;
  utilisé pour /notifications (volume non borné, reste paginé côté back).
- Doc : règle anti-troncature ajoutée au CLAUDE.md.

Déjà protégés (vérifiés) : Task, TimeEntry, TaskDocument, TaskRecurrence,
AbsenceRequest/Policy/Balance (paginationEnabled false) et /time_entries/range.
2026-06-15 11:07:59 +02:00

37 lines
1.2 KiB
TypeScript

import type { Notification } from './dto/notification'
import type { HydraCollection } from '~/utils/api'
import { fetchAllHydra } from '~/utils/api'
export function useNotificationService() {
const api = useApi()
async function getAll(): Promise<Notification[]> {
// La ressource /notifications reste paginée côté back (volume non borné) :
// on suit toutes les pages pour ne pas tronquer la liste à 30 éléments.
return fetchAllHydra<Notification>(page =>
api.get<HydraCollection<Notification>>('/notifications', { page }),
)
}
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 }
}