```
refactor student and teacher APIs to use COL_USER_METAS collection, standardize role assignment, and update type definitions ```
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
// api method for crate student record
|
// api method for crate student record
|
||||||
// RULES:
|
// RULES:
|
||||||
// TBA
|
// TBA
|
||||||
import { COL_STUDENTS, COL_USER_METAS } from '@/constants';
|
import { COL_USER_METAS } from '@/constants';
|
||||||
import type { RecordModel } from 'pocketbase';
|
import type { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
import { pb } from '@/lib/pb';
|
import { pb } from '@/lib/pb';
|
||||||
import type { CreateFormProps } from '@/components/dashboard/student/type.d';
|
import type { CreateFormProps } from '@/components/dashboard/student/type.d';
|
||||||
|
|
||||||
export async function createStudent(data: CreateFormProps): Promise<RecordModel> {
|
export async function createStudent(data: CreateFormProps): Promise<RecordModel> {
|
||||||
return pb.collection(COL_USER_METAS).create(data);
|
return pb.collection(COL_USER_METAS).create({ ...data, role: 'student' });
|
||||||
}
|
}
|
||||||
|
4
002_source/cms/src/db/Students/type.d.ts
vendored
4
002_source/cms/src/db/Students/type.d.ts
vendored
@@ -1,4 +1,6 @@
|
|||||||
import type { BillingAddress } from '@/components/dashboard/user_meta/type.d';
|
//
|
||||||
|
// RULES
|
||||||
|
// type for student record
|
||||||
|
|
||||||
// Student type definitions
|
// Student type definitions
|
||||||
export interface Student {
|
export interface Student {
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
// api method for crate teacher record
|
// api method for crate teacher record
|
||||||
// RULES:
|
// RULES:
|
||||||
// TBA
|
// TBA
|
||||||
import { pb } from '@/lib/pb';
|
import { COL_USER_METAS } from '@/constants';
|
||||||
import { COL_TEACHERS } from '@/constants';
|
|
||||||
import type { CreateFormProps } from '@/components/dashboard/teacher/type.d';
|
|
||||||
import type { RecordModel } from 'pocketbase';
|
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<RecordModel> {
|
export async function createTeacher(data: CreateFormProps): Promise<RecordModel> {
|
||||||
return pb.collection(COL_TEACHERS).create(data);
|
return pb.collection(COL_USER_METAS).create({ ...data, role: 'teacher' });
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
import { pb } from '@/lib/pb';
|
|
||||||
import { COL_TEACHERS } from '@/constants';
|
import { COL_TEACHERS } from '@/constants';
|
||||||
import { RecordModel } from 'pocketbase';
|
import { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
|
||||||
export async function getAllTeachers(options = {}): Promise<RecordModel[]> {
|
export async function getAllTeachers(options = {}): Promise<RecordModel[]> {
|
||||||
return pb.collection(COL_TEACHERS).getFullList(options);
|
return pb.collection(COL_TEACHERS).getFullList(options);
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,28 @@
|
|||||||
import { pb } from '@/lib/pb';
|
import { COL_USER_METAS } from '@/constants';
|
||||||
import { COL_TEACHERS } from '@/constants';
|
|
||||||
import { RecordModel } from 'pocketbase';
|
|
||||||
|
|
||||||
export async function getTeacherById(id: string): Promise<RecordModel> {
|
import { pb } from '@/lib/pb';
|
||||||
return pb.collection(COL_TEACHERS).getOne(id);
|
import type { DBUserMeta, UserMeta } from '@/components/dashboard/user_meta/type.d';
|
||||||
|
|
||||||
|
export async function getTeacherById(id: string): Promise<UserMeta> {
|
||||||
|
const record = await pb.collection(COL_USER_METAS).getOne<DBUserMeta>(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;
|
||||||
}
|
}
|
||||||
|
10
002_source/cms/src/db/Teachers/UpdateById.tsx
Normal file
10
002_source/cms/src/db/Teachers/UpdateById.tsx
Normal file
@@ -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<UpdateTeacher>): Promise<RecordModel> {
|
||||||
|
return pb.collection(COL_USER_METAS).update(id, data);
|
||||||
|
}
|
41
002_source/cms/src/db/Teachers/type.d.ts
vendored
Normal file
41
002_source/cms/src/db/Teachers/type.d.ts
vendored
Normal file
@@ -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<string, never>;
|
||||||
|
|
||||||
|
// status is obsoleted, replace by state
|
||||||
|
// status: 'pending' | 'active' | 'blocked';
|
||||||
|
state?: 'pending' | 'active' | 'blocked';
|
||||||
|
//
|
||||||
|
timezone?: string;
|
||||||
|
language?: string;
|
||||||
|
currency?: string;
|
||||||
|
//
|
||||||
|
taxId?: string;
|
||||||
|
}
|
Reference in New Issue
Block a user