update customer driver,
This commit is contained in:
6
002_source/cms/src/db/Customers/Create.tsx
Normal file
6
002_source/cms/src/db/Customers/Create.tsx
Normal file
@@ -0,0 +1,6 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function createCustomer(data) {
|
||||
return pb.collection(COL_CUSTOMERS).create(data);
|
||||
}
|
6
002_source/cms/src/db/Customers/Delete.tsx
Normal file
6
002_source/cms/src/db/Customers/Delete.tsx
Normal file
@@ -0,0 +1,6 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function deleteCustomer(id) {
|
||||
return pb.collection(COL_CUSTOMERS).delete(id);
|
||||
}
|
9
002_source/cms/src/db/Customers/GetActiveCount.tsx
Normal file
9
002_source/cms/src/db/Customers/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;
|
||||
}
|
6
002_source/cms/src/db/Customers/GetAll.tsx
Normal file
6
002_source/cms/src/db/Customers/GetAll.tsx
Normal file
@@ -0,0 +1,6 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function getAllCustomers(options = {}) {
|
||||
return pb.collection(COL_CUSTOMERS).getFullList(options);
|
||||
}
|
7
002_source/cms/src/db/Customers/GetAllCount.tsx
Normal file
7
002_source/cms/src/db/Customers/GetAllCount.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function getAllCustomersCount() {
|
||||
const result = await pb.collection(COL_CUSTOMERS).getList(1, 1);
|
||||
return result.totalItems;
|
||||
}
|
9
002_source/cms/src/db/Customers/GetBlockedCount.tsx
Normal file
9
002_source/cms/src/db/Customers/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;
|
||||
}
|
6
002_source/cms/src/db/Customers/GetById.tsx
Normal file
6
002_source/cms/src/db/Customers/GetById.tsx
Normal file
@@ -0,0 +1,6 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function getCustomerById(id) {
|
||||
return pb.collection(COL_CUSTOMERS).getOne(id);
|
||||
}
|
9
002_source/cms/src/db/Customers/GetHiddenCount.tsx
Normal file
9
002_source/cms/src/db/Customers/GetHiddenCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function getHiddenCustomersCount() {
|
||||
const result = await pb.collection(COL_CUSTOMERS).getList(1, 1, {
|
||||
filter: 'hidden = true',
|
||||
});
|
||||
return result.totalItems;
|
||||
}
|
9
002_source/cms/src/db/Customers/GetPendingCount.tsx
Normal file
9
002_source/cms/src/db/Customers/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;
|
||||
}
|
9
002_source/cms/src/db/Customers/GetVisibleCount.tsx
Normal file
9
002_source/cms/src/db/Customers/GetVisibleCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function getVisibleCustomersCount() {
|
||||
const result = await pb.collection(COL_CUSTOMERS).getList(1, 1, {
|
||||
filter: 'hidden = false',
|
||||
});
|
||||
return result.totalItems;
|
||||
}
|
3
002_source/cms/src/db/Customers/Helloworld.tsx
Normal file
3
002_source/cms/src/db/Customers/Helloworld.tsx
Normal file
@@ -0,0 +1,3 @@
|
||||
export function helloCustomer() {
|
||||
return 'Hello from Customers module!';
|
||||
}
|
8
002_source/cms/src/db/Customers/Update.tsx
Normal file
8
002_source/cms/src/db/Customers/Update.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import type { RecordModel } from 'pocketbase';
|
||||
import type { CreateForm } from '@/components/dashboard/customer/type.d';
|
||||
|
||||
export async function updateCustomer(id: string, data: Partial<CustomerUpdateData>): Promise<RecordModel> {
|
||||
return pb.collection(COL_CUSTOMERS).update(id, data);
|
||||
}
|
29
002_source/cms/src/db/Customers/_NOTES.md
Normal file
29
002_source/cms/src/db/Customers/_NOTES.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# NOTES
|
||||
|
||||
this folder containing driver for `Customer` / `Customers` record:
|
||||
|
||||
- create (Create.tsx)
|
||||
- read (GetById.tsx)
|
||||
- write (Update.tsx)
|
||||
- count (GetAllCount.tsx, GetHiddenCount.tsx, GetVisibleCount.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
|
||||
|
||||
simple template:
|
||||
|
||||
```typescript
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function createCustomer(data) {
|
||||
// ...content
|
||||
// use direct return of pb.collection (e.g. return pb.collection(xxx))
|
||||
}
|
||||
```
|
Reference in New Issue
Block a user