1.9 KiB
1.9 KiB
GUIDELINES
This folder contains drivers for Notification
/Notifications
(Collection ID: pbc_977978967) records using PocketBase:
File Structure
- create (Create.tsx)
- read (GetById.tsx)
- write (Update.tsx)
- count (GetAllCount.tsx, GetActiveCount.tsx, GetBlockedCount.tsx, GetPendingCount.tsx)
- misc (Helloworld.tsx)
- delete (Delete.tsx)
- list (GetAll.tsx, GetNotificationByUserId.tsx)
Implementation Template
import { pb } from '@/lib/pb';
import { COL_NOTIFICATIONS } from '@/constants';
import type { CreateNotificationProps } from './type.d.ts';
export async function createNotification(data: CreateNotificationProps) {
return pb.collection(COL_NOTIFICATIONS).create(data);
}
Special Considerations
- User-specific notifications (GetNotificationByUserId.tsx)
- Status transitions (active/pending/blocked)
- Priority levels handling
- Expiration dates
- Bulk operations support
Type Definitions
Key types to use:
NotificationStatus
: active|pending|blockedNotificationPriority
: low|medium|highCreateNotificationProps
: Required fieldsUpdateNotificationProps
: Partial updates
Common Patterns
// Bulk creation example
export async function createBulkNotifications(items: CreateNotificationProps[]) {
return Promise.all(items.map(item =>
pb.collection(COL_NOTIFICATIONS).create(item)
));
}
// Status update example
export async function markAsRead(id: string) {
return pb.collection(COL_NOTIFICATIONS).update(id, { status: 'read' });
}
Performance Notes
- Ensure indexes on: user_id, status, created_at
- Consider pagination for large notification lists
- Cache frequently accessed notifications
- Batch operations for mass notifications
Testing Guidelines
Recommended test cases:
- Single notification creation
- Bulk operations
- Status transitions
- User-specific queries
- Error cases (invalid data, permissions)