From d0215cf23ffdeea841abe838bff493e042ca08f8 Mon Sep 17 00:00:00 2001 From: louiscklaw Date: Thu, 15 May 2025 11:12:29 +0800 Subject: [PATCH] ``` refactor GetById APIs for Students, Teachers, and UserMetas to use consistent type definitions and expand parameters ``` --- 002_source/cms/src/db/Students/GetById.tsx | 12 +++++--- 002_source/cms/src/db/Teachers/GetById.tsx | 2 ++ 002_source/cms/src/db/UserMetas/GetById.tsx | 30 +++++++++++++++++-- .../cms/src/db/billingAddress/GetById.tsx | 12 ++++---- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/002_source/cms/src/db/Students/GetById.tsx b/002_source/cms/src/db/Students/GetById.tsx index 1c0cd17..7fda666 100644 --- a/002_source/cms/src/db/Students/GetById.tsx +++ b/002_source/cms/src/db/Students/GetById.tsx @@ -1,12 +1,16 @@ +// src/db/Students/GetById.tsx +// import { COL_USER_METAS } from '@/constants'; import { pb } from '@/lib/pb'; -import type { DBUserMeta, UserMeta } from '@/components/dashboard/user_meta/type.d'; +import type { DBStudent, Student } from '@/components/dashboard/student/type'; -export async function getStudentById(id: string): Promise { - const record = await pb.collection(COL_USER_METAS).getOne(id, { expand: 'billingAddress, helloworld' }); +export async function getStudentById(id: string): Promise { + const record = await pb + .collection(COL_USER_METAS) + .getOne(id, { expand: 'billingAddress, helloworld', requestKey: null }); - const temp: UserMeta = { + const temp: Student = { id: record.id, name: record.name, email: record.email, diff --git a/002_source/cms/src/db/Teachers/GetById.tsx b/002_source/cms/src/db/Teachers/GetById.tsx index bae3928..560d429 100644 --- a/002_source/cms/src/db/Teachers/GetById.tsx +++ b/002_source/cms/src/db/Teachers/GetById.tsx @@ -1,3 +1,5 @@ +// src/db/Teachers/GetById.tsx +// import { COL_USER_METAS } from '@/constants'; import { pb } from '@/lib/pb'; diff --git a/002_source/cms/src/db/UserMetas/GetById.tsx b/002_source/cms/src/db/UserMetas/GetById.tsx index 4b5f721..c93d543 100644 --- a/002_source/cms/src/db/UserMetas/GetById.tsx +++ b/002_source/cms/src/db/UserMetas/GetById.tsx @@ -1,8 +1,32 @@ +// src/db/UserMetas/GetById.tsx +// import { COL_USER_METAS } from '@/constants'; -import type { RecordModel } from 'pocketbase'; import { pb } from '@/lib/pb'; +import type { DBUserMeta, UserMeta } from '@/components/dashboard/user_meta/type'; -export async function getUserMetaById(id: string): Promise { - return pb.collection(COL_USER_METAS).getOne(id, { requestKey: null }); +export async function getUserMetaById(id: string): Promise { + const record = await pb + .collection(COL_USER_METAS) + .getOne(id, { expand: 'billingAddress, helloworld', requestKey: null }); + + const temp: UserMeta = { + id: record.id, + name: record.name, + email: record.email, + quota: record.quota, + billingAddress: record.expand.billingAddress ? record.expand.billingAddress[0] : {}, + status: record.status, + state: record.state, + createdAt: new Date(record.created), + collectionId: record.collectionId, + avatar: record.avatar, + phone: record.phone, + company: record.company, + timezone: record.timezone, + language: record.language, + currency: record.currency, + }; + + return temp; } diff --git a/002_source/cms/src/db/billingAddress/GetById.tsx b/002_source/cms/src/db/billingAddress/GetById.tsx index 0fc5f79..34eb4dd 100644 --- a/002_source/cms/src/db/billingAddress/GetById.tsx +++ b/002_source/cms/src/db/billingAddress/GetById.tsx @@ -1,7 +1,11 @@ -import { COL_BILLING_ADDRESS, COL_STUDENTS, COL_USER_METAS } from '@/constants'; -import { RecordModel } from 'pocketbase'; +// src/db/billingAddress/GetById.tsx +// +// PURPOSE: +// to get billing address by its id +// + +import { COL_BILLING_ADDRESS } from '@/constants'; -import { logger } from '@/lib/default-logger'; import { pb } from '@/lib/pb'; import type { DBUserMeta, UserMeta } from '@/components/dashboard/user_meta/type.d'; @@ -10,8 +14,6 @@ export async function getBillingAddressById(id: string): Promise { .collection(COL_BILLING_ADDRESS) .getOne(id, { expand: 'billingAddress, helloworld' }); - console.log({ record }); - const temp: UserMeta = { id: record.id, name: record.name,