update init teacher ,
This commit is contained in:
11
002_source/cms/src/db/Teachers/Create.tsx
Normal file
11
002_source/cms/src/db/Teachers/Create.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
// 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 type { RecordModel } from 'pocketbase';
|
||||
|
||||
export async function createTeacher(data: CreateFormProps): Promise<RecordModel> {
|
||||
return pb.collection(COL_TEACHERS).create(data);
|
||||
}
|
6
002_source/cms/src/db/Teachers/Delete.tsx
Normal file
6
002_source/cms/src/db/Teachers/Delete.tsx
Normal file
@@ -0,0 +1,6 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_TEACHERS } from '@/constants';
|
||||
|
||||
export async function deleteTeacher(id: string): Promise<boolean> {
|
||||
return pb.collection(COL_TEACHERS).delete(id);
|
||||
}
|
9
002_source/cms/src/db/Teachers/GetActiveCount.tsx
Normal file
9
002_source/cms/src/db/Teachers/GetActiveCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { COL_TEACHERS } from '@/constants';
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
export default async function GetActiveCount(): Promise<number> {
|
||||
const { totalItems: count } = await pb.collection(COL_TEACHERS).getList(1, 1, {
|
||||
filter: 'status = "active"',
|
||||
});
|
||||
return count;
|
||||
}
|
7
002_source/cms/src/db/Teachers/GetAll.tsx
Normal file
7
002_source/cms/src/db/Teachers/GetAll.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_TEACHERS } from '@/constants';
|
||||
import { RecordModel } from 'pocketbase';
|
||||
|
||||
export async function getAllTeachers(options = {}): Promise<RecordModel[]> {
|
||||
return pb.collection(COL_TEACHERS).getFullList(options);
|
||||
}
|
7
002_source/cms/src/db/Teachers/GetAllCount.tsx
Normal file
7
002_source/cms/src/db/Teachers/GetAllCount.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_TEACHERS } from '@/constants';
|
||||
|
||||
export async function getAllTeachersCount(): Promise<number> {
|
||||
const result = await pb.collection(COL_TEACHERS).getList(1, 1);
|
||||
return result.totalItems;
|
||||
}
|
9
002_source/cms/src/db/Teachers/GetBlockedCount.tsx
Normal file
9
002_source/cms/src/db/Teachers/GetBlockedCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { COL_TEACHERS } from '@/constants';
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
export default async function GetBlockedCount(): Promise<number> {
|
||||
const { totalItems: count } = await pb.collection(COL_TEACHERS).getList(1, 1, {
|
||||
filter: 'status = "blocked"',
|
||||
});
|
||||
return count;
|
||||
}
|
7
002_source/cms/src/db/Teachers/GetById.tsx
Normal file
7
002_source/cms/src/db/Teachers/GetById.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_TEACHERS } from '@/constants';
|
||||
import { RecordModel } from 'pocketbase';
|
||||
|
||||
export async function getTeacherById(id: string): Promise<RecordModel> {
|
||||
return pb.collection(COL_TEACHERS).getOne(id);
|
||||
}
|
9
002_source/cms/src/db/Teachers/GetPendingCount.tsx
Normal file
9
002_source/cms/src/db/Teachers/GetPendingCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
export default async function GetPendingCount(): Promise<number> {
|
||||
const { totalItems: count } = await pb.collection(COL_CUSTOMERS).getList(1, 1, {
|
||||
filter: 'status = "pending"',
|
||||
});
|
||||
return count;
|
||||
}
|
3
002_source/cms/src/db/Teachers/Helloworld.tsx
Normal file
3
002_source/cms/src/db/Teachers/Helloworld.tsx
Normal file
@@ -0,0 +1,3 @@
|
||||
export function helloCustomer() {
|
||||
return 'Hello from Customers module!';
|
||||
}
|
8
002_source/cms/src/db/Teachers/Update.tsx
Normal file
8
002_source/cms/src/db/Teachers/Update.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_TEACHERS } from '@/constants';
|
||||
import type { RecordModel } from 'pocketbase';
|
||||
import type { EditFormProps } from '@/components/dashboard/teacher/type.d';
|
||||
|
||||
export async function updateTeacher(id: string, data: Partial<EditFormProps>): Promise<RecordModel> {
|
||||
return pb.collection(COL_TEACHERS).update(id, data);
|
||||
}
|
31
002_source/cms/src/db/Teachers/_GUIDELINES.md
Normal file
31
002_source/cms/src/db/Teachers/_GUIDELINES.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# GUIDELINES
|
||||
|
||||
This folder contains drivers for `Teacher`/`Teachers` records using PocketBase:
|
||||
|
||||
- create (Create.tsx)
|
||||
- read (GetById.tsx)
|
||||
- write (Update.tsx)
|
||||
- count (GetAllCount.tsx, GetActiveCount.tsx, GetBlockedCount.tsx, GetPendingCount.tsx)
|
||||
- misc (Helloworld.tsx)
|
||||
- delete (Delete.tsx)
|
||||
- list (GetAll.tsx)
|
||||
|
||||
the `@` sign refer to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src`
|
||||
|
||||
## Assumption and Requirements
|
||||
|
||||
- assume `pb` is located in `@/lib/pb`
|
||||
- no need to handle error in this function, i'll handle it in the caller
|
||||
- type information defined in `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/Customers/type.d.tsx`
|
||||
|
||||
simple template:
|
||||
|
||||
```typescript
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function createCustomer(data: CreateFormProps) {
|
||||
// ...content
|
||||
// use direct return of pb.collection (e.g. return pb.collection(xxx))
|
||||
}
|
||||
```
|
Reference in New Issue
Block a user