update customer driver,

This commit is contained in:
louiscklaw
2025-04-22 22:55:21 +08:00
parent 7dc7716f18
commit 69cb0718be
13 changed files with 116 additions and 0 deletions

View 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);
}

View 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);
}

View 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;
}

View 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);
}

View 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;
}

View 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;
}

View 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);
}

View 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;
}

View 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;
}

View 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;
}

View File

@@ -0,0 +1,3 @@
export function helloCustomer() {
return 'Hello from Customers module!';
}

View 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);
}

View 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))
}
```