diff --git a/002_source/cms/src/db/Students/Create.tsx b/002_source/cms/src/db/Students/Create.tsx index d9aa24f..3a46b3c 100644 --- a/002_source/cms/src/db/Students/Create.tsx +++ b/002_source/cms/src/db/Students/Create.tsx @@ -1,12 +1,12 @@ // api method for crate student record // RULES: // TBA -import { COL_STUDENTS, COL_USER_METAS } from '@/constants'; +import { COL_USER_METAS } from '@/constants'; import type { RecordModel } from 'pocketbase'; import { pb } from '@/lib/pb'; import type { CreateFormProps } from '@/components/dashboard/student/type.d'; export async function createStudent(data: CreateFormProps): Promise { - return pb.collection(COL_USER_METAS).create(data); + return pb.collection(COL_USER_METAS).create({ ...data, role: 'student' }); } diff --git a/002_source/cms/src/db/Students/type.d.ts b/002_source/cms/src/db/Students/type.d.ts index 32ed267..69759df 100644 --- a/002_source/cms/src/db/Students/type.d.ts +++ b/002_source/cms/src/db/Students/type.d.ts @@ -1,4 +1,6 @@ -import type { BillingAddress } from '@/components/dashboard/user_meta/type.d'; +// +// RULES +// type for student record // Student type definitions export interface Student { diff --git a/002_source/cms/src/db/Teachers/Create.tsx b/002_source/cms/src/db/Teachers/Create.tsx index 836aac6..04fd5d0 100644 --- a/002_source/cms/src/db/Teachers/Create.tsx +++ b/002_source/cms/src/db/Teachers/Create.tsx @@ -1,11 +1,12 @@ // api method for crate teacher record // RULES: // TBA -import { pb } from '@/lib/pb'; -import { COL_TEACHERS } from '@/constants'; -import type { CreateFormProps } from '@/components/dashboard/teacher/type.d'; +import { COL_USER_METAS } from '@/constants'; import type { RecordModel } from 'pocketbase'; +import { pb } from '@/lib/pb'; +import type { CreateFormProps } from '@/components/dashboard/teacher/type.d'; + export async function createTeacher(data: CreateFormProps): Promise { - return pb.collection(COL_TEACHERS).create(data); + return pb.collection(COL_USER_METAS).create({ ...data, role: 'teacher' }); } diff --git a/002_source/cms/src/db/Teachers/GetAll.tsx b/002_source/cms/src/db/Teachers/GetAll.tsx index 323a5c0..d5985d5 100644 --- a/002_source/cms/src/db/Teachers/GetAll.tsx +++ b/002_source/cms/src/db/Teachers/GetAll.tsx @@ -1,7 +1,8 @@ -import { pb } from '@/lib/pb'; import { COL_TEACHERS } from '@/constants'; import { RecordModel } from 'pocketbase'; +import { pb } from '@/lib/pb'; + export async function getAllTeachers(options = {}): Promise { return pb.collection(COL_TEACHERS).getFullList(options); } diff --git a/002_source/cms/src/db/Teachers/GetById.tsx b/002_source/cms/src/db/Teachers/GetById.tsx index db16c4d..bae3928 100644 --- a/002_source/cms/src/db/Teachers/GetById.tsx +++ b/002_source/cms/src/db/Teachers/GetById.tsx @@ -1,7 +1,28 @@ -import { pb } from '@/lib/pb'; -import { COL_TEACHERS } from '@/constants'; -import { RecordModel } from 'pocketbase'; +import { COL_USER_METAS } from '@/constants'; -export async function getTeacherById(id: string): Promise { - return pb.collection(COL_TEACHERS).getOne(id); +import { pb } from '@/lib/pb'; +import type { DBUserMeta, UserMeta } from '@/components/dashboard/user_meta/type.d'; + +export async function getTeacherById(id: string): Promise { + const record = await pb.collection(COL_USER_METAS).getOne(id, { expand: 'billingAddress, helloworld' }); + + 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/Teachers/UpdateById.tsx b/002_source/cms/src/db/Teachers/UpdateById.tsx new file mode 100644 index 0000000..9cd61ab --- /dev/null +++ b/002_source/cms/src/db/Teachers/UpdateById.tsx @@ -0,0 +1,10 @@ +import { COL_USER_METAS } from '@/constants'; +import type { RecordModel } from 'pocketbase'; + +import { pb } from '@/lib/pb'; + +import type { UpdateTeacher } from './type'; + +export async function UpdateTeacherById(id: string, data: Partial): Promise { + return pb.collection(COL_USER_METAS).update(id, data); +} diff --git a/002_source/cms/src/db/Teachers/type.d.ts b/002_source/cms/src/db/Teachers/type.d.ts new file mode 100644 index 0000000..deb4fa2 --- /dev/null +++ b/002_source/cms/src/db/Teachers/type.d.ts @@ -0,0 +1,41 @@ +// +// RULES +// type for teacher record + +// Teacher type definitions +export interface Teacher { + id: string; + name: string; + avatar: string; + email: string; + phone: string; + quota: number; + status: 'active' | 'blocked' | 'pending'; + createdAt: Date; +} + +export interface UpdateTeacher { + name?: string; + // + // NOTE: obslete "avatar" and use "avatar_file" + // avatar_file?: string; + avatar: File | null; + // + email?: string; + phone?: string; + quota?: number; + company?: string; + // + // relation handle seperately + // billingAddress: BillingAddress | Record; + + // status is obsoleted, replace by state + // status: 'pending' | 'active' | 'blocked'; + state?: 'pending' | 'active' | 'blocked'; + // + timezone?: string; + language?: string; + currency?: string; + // + taxId?: string; +}