``update student database operations to use COL_USER_METAS instead of COL_STUDENTS, refactor getStudentById to include expanded billing address data, and add/update related types and functions for student and user meta management
``
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
// api method for crate student record
|
||||
// RULES:
|
||||
// TBA
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_STUDENTS } from '@/constants';
|
||||
import type { CreateFormProps } from '@/components/dashboard/student/type.d';
|
||||
import { COL_STUDENTS, 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<RecordModel> {
|
||||
return pb.collection(COL_STUDENTS).create(data);
|
||||
return pb.collection(COL_USER_METAS).create(data);
|
||||
}
|
||||
|
@@ -1,7 +1,28 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_STUDENTS } from '@/constants';
|
||||
import { RecordModel } from 'pocketbase';
|
||||
import { COL_USER_METAS } from '@/constants';
|
||||
|
||||
export async function getStudentById(id: string): Promise<RecordModel> {
|
||||
return pb.collection(COL_STUDENTS).getOne(id);
|
||||
import { pb } from '@/lib/pb';
|
||||
import type { DBUserMeta, UserMeta } from '@/components/dashboard/user_meta/type.d';
|
||||
|
||||
export async function getStudentById(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/Students/UpdateById.tsx
Normal file
10
002_source/cms/src/db/Students/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 { UpdateStudent } from './type';
|
||||
|
||||
export async function UpdateStudentById(id: string, data: Partial<UpdateStudent>): Promise<RecordModel> {
|
||||
return pb.collection(COL_USER_METAS).update(id, data);
|
||||
}
|
28
002_source/cms/src/db/Students/type.d.ts
vendored
28
002_source/cms/src/db/Students/type.d.ts
vendored
@@ -1,3 +1,5 @@
|
||||
import type { BillingAddress } from '@/components/dashboard/user_meta/type.d';
|
||||
|
||||
// Student type definitions
|
||||
export interface Student {
|
||||
id: string;
|
||||
@@ -9,3 +11,29 @@ export interface Student {
|
||||
status: 'active' | 'blocked' | 'pending';
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
export interface UpdateStudent {
|
||||
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;
|
||||
}
|
||||
|
10
002_source/cms/src/db/UserMetas/UpdateById.tsx
Normal file
10
002_source/cms/src/db/UserMetas/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 { UpdateUserMeta } from './type';
|
||||
|
||||
export async function UpdateUserMetaById(id: string, data: Partial<UpdateUserMeta>): Promise<RecordModel> {
|
||||
return pb.collection(COL_USER_METAS).update(id, data);
|
||||
}
|
39
002_source/cms/src/db/UserMetas/type.d.ts
vendored
Normal file
39
002_source/cms/src/db/UserMetas/type.d.ts
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
import type { BillingAddress } from '@/components/dashboard/user_meta/type.d';
|
||||
|
||||
// UserMeta type definitions
|
||||
export interface UserMeta {
|
||||
id: string;
|
||||
name: string;
|
||||
avatar: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
quota: number;
|
||||
status: 'active' | 'blocked' | 'pending';
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
export interface UpdateUserMeta {
|
||||
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