update notifications,
This commit is contained in:
11
002_source/cms/src/db/Notifications/Create.tsx
Normal file
11
002_source/cms/src/db/Notifications/Create.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
// api method for create notification record
|
||||
// RULES:
|
||||
// TBA
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_NOTIFICATIONS } from '@/constants';
|
||||
import type { NotificationFormProps } from '@/components/dashboard/notification/type.d';
|
||||
import type { RecordModel } from 'pocketbase';
|
||||
|
||||
export async function createNotification(data: NotificationFormProps): Promise<RecordModel> {
|
||||
return pb.collection(COL_NOTIFICATIONS).create(data);
|
||||
}
|
9
002_source/cms/src/db/Notifications/Delete.tsx
Normal file
9
002_source/cms/src/db/Notifications/Delete.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
// api method for delete notification record
|
||||
// RULES:
|
||||
// TBA
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_NOTIFICATIONS } from '@/constants';
|
||||
|
||||
export async function deleteNotification(id: string): Promise<boolean> {
|
||||
return pb.collection(COL_NOTIFICATIONS).delete(id);
|
||||
}
|
9
002_source/cms/src/db/Notifications/GetActiveCount.tsx
Normal file
9
002_source/cms/src/db/Notifications/GetActiveCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
export default async function GetActiveCount(): Promise<number> {
|
||||
const { totalItems: count } = await pb.collection(COL_CUSTOMERS).getList(1, 1, {
|
||||
filter: 'status = "active"',
|
||||
});
|
||||
return count;
|
||||
}
|
10
002_source/cms/src/db/Notifications/GetAll.tsx
Normal file
10
002_source/cms/src/db/Notifications/GetAll.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
// api method for get all notification records
|
||||
// RULES:
|
||||
// TBA
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_NOTIFICATIONS } from '@/constants';
|
||||
import { RecordModel } from 'pocketbase';
|
||||
|
||||
export async function getAllNotifications(options = {}): Promise<RecordModel[]> {
|
||||
return pb.collection(COL_NOTIFICATIONS).getFullList(options);
|
||||
}
|
7
002_source/cms/src/db/Notifications/GetAllCount.tsx
Normal file
7
002_source/cms/src/db/Notifications/GetAllCount.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function getAllCustomersCount(): Promise<number> {
|
||||
const result = await pb.collection(COL_CUSTOMERS).getList(1, 1);
|
||||
return result.totalItems;
|
||||
}
|
9
002_source/cms/src/db/Notifications/GetBlockedCount.tsx
Normal file
9
002_source/cms/src/db/Notifications/GetBlockedCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
export default async function GetBlockedCount(): Promise<number> {
|
||||
const { totalItems: count } = await pb.collection(COL_CUSTOMERS).getList(1, 1, {
|
||||
filter: 'status = "blocked"',
|
||||
});
|
||||
return count;
|
||||
}
|
10
002_source/cms/src/db/Notifications/GetById.tsx
Normal file
10
002_source/cms/src/db/Notifications/GetById.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
// api method for get notification by id
|
||||
// RULES:
|
||||
// TBA
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_NOTIFICATIONS } from '@/constants';
|
||||
import { RecordModel } from 'pocketbase';
|
||||
|
||||
export async function getNotificationById(id: string): Promise<RecordModel> {
|
||||
return pb.collection(COL_NOTIFICATIONS).getOne(id);
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
// api method for get notifications by user id
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_NOTIFICATIONS } from '@/constants';
|
||||
import type { Notification } from './type.d';
|
||||
|
||||
export async function getNotificationsByUserId(userId: string): Promise<Notification[]> {
|
||||
const records = await pb.collection(COL_NOTIFICATIONS).getFullList({
|
||||
filter: `author.id = "000000000000001"`,
|
||||
sort: '-created',
|
||||
});
|
||||
return records as unknown as Notification[];
|
||||
}
|
9
002_source/cms/src/db/Notifications/GetPendingCount.tsx
Normal file
9
002_source/cms/src/db/Notifications/GetPendingCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
export default async function GetPendingCount(): Promise<number> {
|
||||
const { totalItems: count } = await pb.collection(COL_CUSTOMERS).getList(1, 1, {
|
||||
filter: 'status = "pending"',
|
||||
});
|
||||
return count;
|
||||
}
|
3
002_source/cms/src/db/Notifications/Helloworld.tsx
Normal file
3
002_source/cms/src/db/Notifications/Helloworld.tsx
Normal file
@@ -0,0 +1,3 @@
|
||||
export function helloCustomer() {
|
||||
return 'Hello from Customers module!';
|
||||
}
|
11
002_source/cms/src/db/Notifications/Update.tsx
Normal file
11
002_source/cms/src/db/Notifications/Update.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
// api method for update notification record
|
||||
// RULES:
|
||||
// TBA
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_NOTIFICATIONS } from '@/constants';
|
||||
import type { RecordModel } from 'pocketbase';
|
||||
import type { NotificationFormProps } from '@/components/dashboard/notification/type.d';
|
||||
|
||||
export async function updateNotification(id: string, data: Partial<NotificationFormProps>): Promise<RecordModel> {
|
||||
return pb.collection(COL_NOTIFICATIONS).update(id, data);
|
||||
}
|
31
002_source/cms/src/db/Notifications/_GUIDELINES.md
Normal file
31
002_source/cms/src/db/Notifications/_GUIDELINES.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# GUIDELINES
|
||||
|
||||
This folder contains drivers for `Customer`/`Customers` records using PocketBase:
|
||||
|
||||
- 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)
|
||||
|
||||
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:
|
||||
|
||||
```typescript
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function createCustomer(data: CreateFormProps) {
|
||||
// ...content
|
||||
// use direct return of pb.collection (e.g. return pb.collection(xxx))
|
||||
}
|
||||
```
|
19
002_source/cms/src/db/Notifications/constants.ts
Normal file
19
002_source/cms/src/db/Notifications/constants.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
// Default and empty values for Notification
|
||||
|
||||
import type { Notification } from './type';
|
||||
|
||||
export const defaultNotification: Notification = {
|
||||
id: '',
|
||||
read: false,
|
||||
type: '',
|
||||
author: {},
|
||||
job: {},
|
||||
description: '',
|
||||
NOTI_ID: '',
|
||||
created: '',
|
||||
updated: '',
|
||||
};
|
||||
|
||||
export const emptyNotification: Notification = {
|
||||
...defaultNotification,
|
||||
};
|
45
002_source/cms/src/db/Notifications/type.d.ts
vendored
Normal file
45
002_source/cms/src/db/Notifications/type.d.ts
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
'use client';
|
||||
|
||||
export type SortDir = 'asc' | 'desc';
|
||||
|
||||
export interface Notification {
|
||||
id: string;
|
||||
read: boolean;
|
||||
type: string;
|
||||
author: Record<string, unknown>;
|
||||
job: Record<string, unknown>;
|
||||
description: string;
|
||||
NOTI_ID: string;
|
||||
created: string;
|
||||
updated: string;
|
||||
}
|
||||
|
||||
export interface CreateFormProps {
|
||||
read?: boolean;
|
||||
type: string;
|
||||
author: Record<string, unknown>;
|
||||
job: Record<string, unknown>;
|
||||
description: string;
|
||||
NOTI_ID: string;
|
||||
}
|
||||
|
||||
export interface EditFormProps {
|
||||
read?: boolean;
|
||||
type?: string;
|
||||
author?: Record<string, unknown>;
|
||||
job?: Record<string, unknown>;
|
||||
description?: string;
|
||||
NOTI_ID?: string;
|
||||
}
|
||||
|
||||
export interface NotificationsFiltersProps {
|
||||
filters?: Filters;
|
||||
sortDir?: SortDir;
|
||||
fullData: Notification[];
|
||||
}
|
||||
|
||||
export interface Filters {
|
||||
type?: string;
|
||||
read?: boolean;
|
||||
NOTI_ID?: string;
|
||||
}
|
Reference in New Issue
Block a user