update,
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
# GUIDELINES
|
||||
|
||||
This folder contains drivers for `Customer`/`Customers` records using PocketBase:
|
||||
This folder contains drivers for `Notification`/`Notifications` (Collection ID: pbc_977978967) records using PocketBase:
|
||||
|
||||
## File Structure
|
||||
|
||||
- create (Create.tsx)
|
||||
- read (GetById.tsx)
|
||||
@@ -8,24 +10,66 @@ This folder contains drivers for `Customer`/`Customers` records using PocketBase
|
||||
- count (GetAllCount.tsx, GetActiveCount.tsx, GetBlockedCount.tsx, GetPendingCount.tsx)
|
||||
- misc (Helloworld.tsx)
|
||||
- delete (Delete.tsx)
|
||||
- list (GetAll.tsx)
|
||||
- list (GetAll.tsx, GetNotificationByUserId.tsx)
|
||||
|
||||
the `@` sign refer to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src`
|
||||
|
||||
## Assumption and Requirements
|
||||
|
||||
- assume `pb` is located in `@/lib/pb`
|
||||
- no need to handle error in this function, i'll handle it in the caller
|
||||
- type information defined in `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/Customers/type.d.tsx`
|
||||
|
||||
simple template:
|
||||
## Implementation Template
|
||||
|
||||
```typescript
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { COL_NOTIFICATIONS } from '@/constants';
|
||||
import type { CreateNotificationProps } from './type.d.ts';
|
||||
|
||||
export async function createCustomer(data: CreateFormProps) {
|
||||
// ...content
|
||||
// use direct return of pb.collection (e.g. return pb.collection(xxx))
|
||||
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|blocked
|
||||
- `NotificationPriority`: low|medium|high
|
||||
- `CreateNotificationProps`: Required fields
|
||||
- `UpdateNotificationProps`: Partial updates
|
||||
|
||||
## Common Patterns
|
||||
|
||||
```typescript
|
||||
// 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)
|
||||
|
Reference in New Issue
Block a user