diff --git a/002_source/cms/src/db/Customers/Create.tsx b/002_source/cms/src/db/Customers/Create.tsx new file mode 100644 index 0000000..436eb72 --- /dev/null +++ b/002_source/cms/src/db/Customers/Create.tsx @@ -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); +} diff --git a/002_source/cms/src/db/Customers/Delete.tsx b/002_source/cms/src/db/Customers/Delete.tsx new file mode 100644 index 0000000..63cabb8 --- /dev/null +++ b/002_source/cms/src/db/Customers/Delete.tsx @@ -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); +} diff --git a/002_source/cms/src/db/Customers/GetActiveCount.tsx b/002_source/cms/src/db/Customers/GetActiveCount.tsx new file mode 100644 index 0000000..a8679de --- /dev/null +++ b/002_source/cms/src/db/Customers/GetActiveCount.tsx @@ -0,0 +1,9 @@ +import { COL_CUSTOMERS } from '@/constants'; +import { pb } from '@/lib/pb'; + +export default async function GetActiveCount(): Promise { + const { totalItems: count } = await pb.collection(COL_CUSTOMERS).getList(1, 1, { + filter: 'status = "active"', + }); + return count; +} diff --git a/002_source/cms/src/db/Customers/GetAll.tsx b/002_source/cms/src/db/Customers/GetAll.tsx new file mode 100644 index 0000000..f88ef0d --- /dev/null +++ b/002_source/cms/src/db/Customers/GetAll.tsx @@ -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); +} diff --git a/002_source/cms/src/db/Customers/GetAllCount.tsx b/002_source/cms/src/db/Customers/GetAllCount.tsx new file mode 100644 index 0000000..139bd7a --- /dev/null +++ b/002_source/cms/src/db/Customers/GetAllCount.tsx @@ -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; +} diff --git a/002_source/cms/src/db/Customers/GetBlockedCount.tsx b/002_source/cms/src/db/Customers/GetBlockedCount.tsx new file mode 100644 index 0000000..261321c --- /dev/null +++ b/002_source/cms/src/db/Customers/GetBlockedCount.tsx @@ -0,0 +1,9 @@ +import { COL_CUSTOMERS } from '@/constants'; +import { pb } from '@/lib/pb'; + +export default async function GetBlockedCount(): Promise { + const { totalItems: count } = await pb.collection(COL_CUSTOMERS).getList(1, 1, { + filter: 'status = "blocked"', + }); + return count; +} diff --git a/002_source/cms/src/db/Customers/GetById.tsx b/002_source/cms/src/db/Customers/GetById.tsx new file mode 100644 index 0000000..d8392c1 --- /dev/null +++ b/002_source/cms/src/db/Customers/GetById.tsx @@ -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); +} diff --git a/002_source/cms/src/db/Customers/GetHiddenCount.tsx b/002_source/cms/src/db/Customers/GetHiddenCount.tsx new file mode 100644 index 0000000..5352394 --- /dev/null +++ b/002_source/cms/src/db/Customers/GetHiddenCount.tsx @@ -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; +} diff --git a/002_source/cms/src/db/Customers/GetPendingCount.tsx b/002_source/cms/src/db/Customers/GetPendingCount.tsx new file mode 100644 index 0000000..d6661ca --- /dev/null +++ b/002_source/cms/src/db/Customers/GetPendingCount.tsx @@ -0,0 +1,9 @@ +import { COL_CUSTOMERS } from '@/constants'; +import { pb } from '@/lib/pb'; + +export default async function GetPendingCount(): Promise { + const { totalItems: count } = await pb.collection(COL_CUSTOMERS).getList(1, 1, { + filter: 'status = "pending"', + }); + return count; +} diff --git a/002_source/cms/src/db/Customers/GetVisibleCount.tsx b/002_source/cms/src/db/Customers/GetVisibleCount.tsx new file mode 100644 index 0000000..f610a97 --- /dev/null +++ b/002_source/cms/src/db/Customers/GetVisibleCount.tsx @@ -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; +} diff --git a/002_source/cms/src/db/Customers/Helloworld.tsx b/002_source/cms/src/db/Customers/Helloworld.tsx new file mode 100644 index 0000000..2487997 --- /dev/null +++ b/002_source/cms/src/db/Customers/Helloworld.tsx @@ -0,0 +1,3 @@ +export function helloCustomer() { + return 'Hello from Customers module!'; +} diff --git a/002_source/cms/src/db/Customers/Update.tsx b/002_source/cms/src/db/Customers/Update.tsx new file mode 100644 index 0000000..a42caab --- /dev/null +++ b/002_source/cms/src/db/Customers/Update.tsx @@ -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): Promise { + return pb.collection(COL_CUSTOMERS).update(id, data); +} diff --git a/002_source/cms/src/db/Customers/_NOTES.md b/002_source/cms/src/db/Customers/_NOTES.md new file mode 100644 index 0000000..6fb9118 --- /dev/null +++ b/002_source/cms/src/db/Customers/_NOTES.md @@ -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)) +} +```