diff --git a/002_source/cms/src/app/dashboard/users/create/page.tsx b/002_source/cms/src/app/dashboard/users/create/page.tsx index 98b2ec9..d9a595d 100644 --- a/002_source/cms/src/app/dashboard/users/create/page.tsx +++ b/002_source/cms/src/app/dashboard/users/create/page.tsx @@ -9,9 +9,9 @@ import { ArrowLeft as ArrowLeftIcon } from '@phosphor-icons/react/dist/ssr/Arrow import { config } from '@/config'; import { paths } from '@/paths'; -import { CustomerCreateForm } from '@/components/dashboard/student/student-create-form'; +import { UserCreateForm } from '@/components/dashboard/user/user-create-form'; -export const metadata = { title: `Create | Customers | Dashboard | ${config.site.name}` } satisfies Metadata; +export const metadata = { title: `Create | Users | Dashboard | ${config.site.name}` } satisfies Metadata; export default function Page(): React.JSX.Element { return ( @@ -29,19 +29,19 @@ export default function Page(): React.JSX.Element { - Customers + Users
- Create customer + Create user
- + ); diff --git a/002_source/cms/src/app/dashboard/users/edit/[customerId]/_PROMPT.md b/002_source/cms/src/app/dashboard/users/edit/[id]/_PROMPT.md similarity index 100% rename from 002_source/cms/src/app/dashboard/users/edit/[customerId]/_PROMPT.md rename to 002_source/cms/src/app/dashboard/users/edit/[id]/_PROMPT.md diff --git a/002_source/cms/src/app/dashboard/users/edit/[customerId]/page.tsx b/002_source/cms/src/app/dashboard/users/edit/[id]/page.tsx similarity index 86% rename from 002_source/cms/src/app/dashboard/users/edit/[customerId]/page.tsx rename to 002_source/cms/src/app/dashboard/users/edit/[id]/page.tsx index 8b623fd..da46923 100644 --- a/002_source/cms/src/app/dashboard/users/edit/[customerId]/page.tsx +++ b/002_source/cms/src/app/dashboard/users/edit/[id]/page.tsx @@ -11,10 +11,10 @@ import { useTranslation } from 'react-i18next'; import { paths } from '@/paths'; import { CrCategoryEditForm } from '@/components/dashboard/cr/categories/cr-category-edit-form'; -import { StudentEditForm } from '@/components/dashboard/student/student-edit-form'; +import { UserEditForm } from '@/components/dashboard/user/user-edit-form'; export default function Page(): React.JSX.Element { - const { t } = useTranslation(['lp_categories']); + const { t } = useTranslation(['users']); React.useEffect(() => { // console.log('helloworld'); @@ -35,7 +35,7 @@ export default function Page(): React.JSX.Element { @@ -47,7 +47,7 @@ export default function Page(): React.JSX.Element { {t('edit.title')} - + ); diff --git a/002_source/cms/src/db/UserMetas/Create.tsx b/002_source/cms/src/db/UserMetas/Create.tsx new file mode 100644 index 0000000..957f577 --- /dev/null +++ b/002_source/cms/src/db/UserMetas/Create.tsx @@ -0,0 +1,11 @@ +// api method for crate customer record +// RULES: +// TBA +import { pb } from '@/lib/pb'; +import { COL_CUSTOMERS } from '@/constants'; +import type { CreateFormProps } from '@/components/dashboard/customer/type.d'; +import type { RecordModel } from 'pocketbase'; + +export async function createCustomer(data: CreateFormProps): Promise { + return pb.collection(COL_CUSTOMERS).create(data); +} diff --git a/002_source/cms/src/db/UserMetas/Delete.tsx b/002_source/cms/src/db/UserMetas/Delete.tsx new file mode 100644 index 0000000..52760f1 --- /dev/null +++ b/002_source/cms/src/db/UserMetas/Delete.tsx @@ -0,0 +1,6 @@ +import { pb } from '@/lib/pb'; +import { COL_CUSTOMERS } from '@/constants'; + +export async function deleteCustomer(id: string): Promise { + return pb.collection(COL_CUSTOMERS).delete(id); +} diff --git a/002_source/cms/src/db/UserMetas/GetActiveCount.tsx b/002_source/cms/src/db/UserMetas/GetActiveCount.tsx new file mode 100644 index 0000000..a8679de --- /dev/null +++ b/002_source/cms/src/db/UserMetas/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/UserMetas/GetAll.tsx b/002_source/cms/src/db/UserMetas/GetAll.tsx new file mode 100644 index 0000000..1130771 --- /dev/null +++ b/002_source/cms/src/db/UserMetas/GetAll.tsx @@ -0,0 +1,7 @@ +import { pb } from '@/lib/pb'; +import { COL_CUSTOMERS } from '@/constants'; +import { RecordModel } from 'pocketbase'; + +export async function getAllCustomers(options = {}): Promise { + return pb.collection(COL_CUSTOMERS).getFullList(options); +} diff --git a/002_source/cms/src/db/UserMetas/GetBlockedCount.tsx b/002_source/cms/src/db/UserMetas/GetBlockedCount.tsx new file mode 100644 index 0000000..261321c --- /dev/null +++ b/002_source/cms/src/db/UserMetas/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/UserMetas/GetById.tsx b/002_source/cms/src/db/UserMetas/GetById.tsx new file mode 100644 index 0000000..7c8ef98 --- /dev/null +++ b/002_source/cms/src/db/UserMetas/GetById.tsx @@ -0,0 +1,7 @@ +import { pb } from '@/lib/pb'; +import { COL_CUSTOMERS } from '@/constants'; +import { RecordModel } from 'pocketbase'; + +export async function getCustomerById(id: string): Promise { + return pb.collection(COL_CUSTOMERS).getOne(id); +} diff --git a/002_source/cms/src/db/UserMetas/GetPendingCount.tsx b/002_source/cms/src/db/UserMetas/GetPendingCount.tsx new file mode 100644 index 0000000..d6661ca --- /dev/null +++ b/002_source/cms/src/db/UserMetas/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/UserMetas/Helloworld.tsx b/002_source/cms/src/db/UserMetas/Helloworld.tsx new file mode 100644 index 0000000..2487997 --- /dev/null +++ b/002_source/cms/src/db/UserMetas/Helloworld.tsx @@ -0,0 +1,3 @@ +export function helloCustomer() { + return 'Hello from Customers module!'; +} diff --git a/002_source/cms/src/db/UserMetas/Update.tsx b/002_source/cms/src/db/UserMetas/Update.tsx new file mode 100644 index 0000000..7beeff7 --- /dev/null +++ b/002_source/cms/src/db/UserMetas/Update.tsx @@ -0,0 +1,8 @@ +import { pb } from '@/lib/pb'; +import { COL_CUSTOMERS } from '@/constants'; +import type { RecordModel } from 'pocketbase'; +import type { EditFormProps } 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/UserMetas/_GUIDELINES.md b/002_source/cms/src/db/UserMetas/_GUIDELINES.md index 40c2a38..00da7f6 100644 --- a/002_source/cms/src/db/UserMetas/_GUIDELINES.md +++ b/002_source/cms/src/db/UserMetas/_GUIDELINES.md @@ -1,11 +1,12 @@ # GUIDELINES -This folder contains drivers for `UserMeta`/`UserMetas` records using PocketBase: +This folder contains drivers for `Customer`/`Customers`(Collection ID: pbc_108570809) records using PocketBase: - create (Create.tsx) - read (GetById.tsx) - write (Update.tsx) -- count (GetAllCount.tsx) +- count (GetAllCount.tsx, GetActiveCount.tsx, GetBlockedCount.tsx, GetPendingCount.tsx) +- misc (Helloworld.tsx) - delete (Delete.tsx) - list (GetAll.tsx) @@ -15,15 +16,15 @@ the `@` sign refer to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-onlin - 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 `@/db/UserMetas/type.d.tsx` +- 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_USER_METAS } from '@/constants'; +import { COL_CUSTOMERS } from '@/constants'; -export async function createUserMeta(data: CreateFormProps) { +export async function createCustomer(data: CreateFormProps) { // ...content // use direct return of pb.collection (e.g. return pb.collection(xxx)) } diff --git a/002_source/cms/src/db/Users/Create.tsx b/002_source/cms/src/db/Users/Create.tsx new file mode 100644 index 0000000..c6bdf7a --- /dev/null +++ b/002_source/cms/src/db/Users/Create.tsx @@ -0,0 +1,15 @@ +import { pb } from '@/lib/pb'; +import { COL_USERS } from '@/constants'; +import type { User } from '@/types/user'; + +export async function createUser(userData: Partial): Promise<{ + data?: User; + error?: Error; +}> { + try { + const data = await pb.collection(COL_USERS).create(userData); + return { data }; + } catch (error) { + return { error: error as Error }; + } +} diff --git a/002_source/cms/src/db/Users/Delete.tsx b/002_source/cms/src/db/Users/Delete.tsx new file mode 100644 index 0000000..d1a0b73 --- /dev/null +++ b/002_source/cms/src/db/Users/Delete.tsx @@ -0,0 +1,14 @@ +import { pb } from '@/lib/pb'; +import { COL_USERS } from '@/constants'; + +export async function deleteUserById(id: string): Promise { + try { + await pb.collection(COL_USERS).delete(id); + return true; + } catch (err) { + if (err instanceof Error && err.message.includes('404')) { + throw new Error(`User with ID ${id} not found`); + } + throw err; + } +} diff --git a/002_source/cms/src/db/Users/GetActiveCount.tsx b/002_source/cms/src/db/Users/GetActiveCount.tsx new file mode 100644 index 0000000..a8679de --- /dev/null +++ b/002_source/cms/src/db/Users/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/Users/GetAll.tsx b/002_source/cms/src/db/Users/GetAll.tsx new file mode 100644 index 0000000..1130771 --- /dev/null +++ b/002_source/cms/src/db/Users/GetAll.tsx @@ -0,0 +1,7 @@ +import { pb } from '@/lib/pb'; +import { COL_CUSTOMERS } from '@/constants'; +import { RecordModel } from 'pocketbase'; + +export async function getAllCustomers(options = {}): Promise { + return pb.collection(COL_CUSTOMERS).getFullList(options); +} diff --git a/002_source/cms/src/db/Users/GetAllCount.tsx b/002_source/cms/src/db/Users/GetAllCount.tsx index b82dc88..701ba1e 100644 --- a/002_source/cms/src/db/Users/GetAllCount.tsx +++ b/002_source/cms/src/db/Users/GetAllCount.tsx @@ -1,15 +1,7 @@ -// REQ0006 +import { pb } from '@/lib/pb'; import { COL_USERS } from '@/constants'; -import { pb } from '@/lib/pb'; - -export default async function GetAllCount(): Promise { - try { - const result = await pb.collection(`users`).getList(1, 9999, { filter: 'email != ""' }); - const { totalItems: count } = result; - return count; - } catch (error) { - console.error(error); - return -99; - } +export async function GetAllUsersCount(): Promise { + const result = await pb.collection(COL_USERS).getList(1, 1); + return result.totalItems; } diff --git a/002_source/cms/src/db/Users/GetBlockedCount.tsx b/002_source/cms/src/db/Users/GetBlockedCount.tsx new file mode 100644 index 0000000..261321c --- /dev/null +++ b/002_source/cms/src/db/Users/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/Users/GetById.tsx b/002_source/cms/src/db/Users/GetById.tsx new file mode 100644 index 0000000..f313892 --- /dev/null +++ b/002_source/cms/src/db/Users/GetById.tsx @@ -0,0 +1,15 @@ +import { pb } from '@/lib/pb'; +import { COL_USERS } from '@/constants'; +import type { User } from '@/types/user'; + +export async function getUserById(id: string): Promise { + try { + const user = await pb.collection(COL_USERS).getOne(id); + return user; + } catch (err) { + if (err instanceof Error && err.message.includes('404')) { + throw new Error(`User with ID ${id} not found`); + } + throw err; + } +} diff --git a/002_source/cms/src/db/Users/GetPendingCount.tsx b/002_source/cms/src/db/Users/GetPendingCount.tsx new file mode 100644 index 0000000..186c743 --- /dev/null +++ b/002_source/cms/src/db/Users/GetPendingCount.tsx @@ -0,0 +1,9 @@ +import { COL_USERS } from '@/constants'; +import { pb } from '@/lib/pb'; + +export default async function GetPendingCount(): Promise { + const { totalItems: count } = await pb.collection(COL_USERS).getList(1, 1, { + filter: 'status = "pending"', + }); + return count; +} diff --git a/002_source/cms/src/db/Users/Helloworld.tsx b/002_source/cms/src/db/Users/Helloworld.tsx new file mode 100644 index 0000000..efbb76d --- /dev/null +++ b/002_source/cms/src/db/Users/Helloworld.tsx @@ -0,0 +1,3 @@ +export function helloUser() { + return 'Hello from Users module!'; +} diff --git a/002_source/cms/src/db/Users/Update.tsx b/002_source/cms/src/db/Users/Update.tsx new file mode 100644 index 0000000..8a4bf79 --- /dev/null +++ b/002_source/cms/src/db/Users/Update.tsx @@ -0,0 +1,21 @@ +import { pb } from '@/lib/pb'; +import { COL_USERS } from '@/constants'; +import type { User } from '@/types/user'; + +export async function updateUser( + id: string, + data: Partial +): Promise<{ + data?: User; + error?: Error; +}> { + try { + const updatedUser = await pb.collection(COL_USERS).update(id, data); + return { data: updatedUser }; + } catch (error) { + if (error instanceof Error && error.message.includes('404')) { + return { error: new Error(`User with ID ${id} not found`) }; + } + return { error: error as Error }; + } +} diff --git a/002_source/cms/src/db/Users/_GUIDELINES.md b/002_source/cms/src/db/Users/_GUIDELINES.md index 17cc639..0c42524 100644 --- a/002_source/cms/src/db/Users/_GUIDELINES.md +++ b/002_source/cms/src/db/Users/_GUIDELINES.md @@ -5,7 +5,8 @@ This folder contains drivers for `User`/`Users` records using PocketBase: - create (Create.tsx) - read (GetById.tsx) - write (Update.tsx) -- count (GetAllCount.tsx) +- count (GetAllCount.tsx, GetActiveCount.tsx, GetBlockedCount.tsx, GetPendingCount.tsx) +- misc (Helloworld.tsx) - delete (Delete.tsx) - list (GetAll.tsx) @@ -15,7 +16,7 @@ the `@` sign refer to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-onlin - 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 `@/db/Users/type.d.tsx` +- type information defined in `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/Users/type.d.tsx` simple template: