Files
lettersoup-online/002_source/cms/src/db/Students/GetById.tsx
louiscklaw d0215cf23f ```
refactor GetById APIs for Students, Teachers, and UserMetas to use consistent type definitions and expand parameters
```
2025-05-15 11:12:29 +08:00

33 lines
944 B
TypeScript

// src/db/Students/GetById.tsx
//
import { COL_USER_METAS } from '@/constants';
import { pb } from '@/lib/pb';
import type { DBStudent, Student } from '@/components/dashboard/student/type';
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: Student = {
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;
}