refactor GetById APIs for Students, Teachers, and UserMetas to use consistent type definitions and expand parameters
```
This commit is contained in:
louiscklaw
2025-05-15 11:12:29 +08:00
parent e523f80123
commit d0215cf23f
4 changed files with 44 additions and 12 deletions

View File

@@ -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<UserMeta> {
const record = await pb.collection(COL_USER_METAS).getOne<DBUserMeta>(id, { expand: 'billingAddress, helloworld' });
export async function getStudentById(id: string): Promise<Student> {
const record = await pb
.collection(COL_USER_METAS)
.getOne<DBStudent>(id, { expand: 'billingAddress, helloworld', requestKey: null });
const temp: UserMeta = {
const temp: Student = {
id: record.id,
name: record.name,
email: record.email,

View File

@@ -1,3 +1,5 @@
// src/db/Teachers/GetById.tsx
//
import { COL_USER_METAS } from '@/constants';
import { pb } from '@/lib/pb';

View File

@@ -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<RecordModel> {
return pb.collection(COL_USER_METAS).getOne(id, { requestKey: null });
export async function getUserMetaById(id: string): Promise<UserMeta> {
const record = await pb
.collection(COL_USER_METAS)
.getOne<DBUserMeta>(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;
}

View File

@@ -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<UserMeta> {
.collection(COL_BILLING_ADDRESS)
.getOne<DBUserMeta>(id, { expand: 'billingAddress, helloworld' });
console.log({ record });
const temp: UserMeta = {
id: record.id,
name: record.name,