update Implement standardized documentation for all database modules, including purpose, rules, and requirements for each CRUD operation; refactor existing comments to follow new documentation standard ```
28 lines
853 B
TypeScript
28 lines
853 B
TypeScript
// 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<Notification[]>
|
|
// 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<Notification[]> {
|
|
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[];
|
|
}
|