// PURPOSE: // Get all unread notifications for specified user ID // // RULES: // 1. Uses COL_NOTIFICATIONS collection // 2. Filters by to_user_id and read=false status // 3. Expands author and to_user_id relations // 4. Sorts by created date (newest first) // 5. Returns Promise // 6. Disables caching for real-time results import { COL_NOTIFICATIONS } from '@/constants'; import { pb } from '@/lib/pb'; import type { Notification } from './type.d'; export async function getUnreadNotificationsByUserId(userId: string): Promise { const records = await pb.collection(COL_NOTIFICATIONS).getFullList({ expand: 'author, to_user_id', filter: `to_user_id.id = "${userId}" && read = false`, sort: '-created', cache: 'no-cache', requestKey: null, }); return records as unknown as Notification[]; }