This commit is contained in:
louiscklaw
2025-04-26 06:15:18 +08:00
parent df87cfb037
commit 6e8fea3bdd
57 changed files with 1392 additions and 20183 deletions

View File

@@ -0,0 +1,13 @@
//
// RULES:
import { COL_LESSON_CATEGORIES } from '@/constants';
import { pb } from '@/lib/pb';
import type { LessonCategory } from './type';
export async function listLessonCategories(): Promise<LessonCategory[]> {
const records = await pb.collection(COL_LESSON_CATEGORIES).getFullList({
expand: 'cat_id',
});
return records as unknown as LessonCategory[];
}

View File

@@ -0,0 +1,23 @@
export interface LessonCategory {
isEmpty?: boolean;
//
id: string;
collectionId: string;
//
cat_name: string;
cat_image_url?: string;
cat_image?: string;
pos: number;
visible: string;
lesson_id: string;
description: string;
remarks: string;
createdAt: Date;
//
name: string;
avatar: string;
email: string;
phone: string;
quota: number;
status: 'pending' | 'active' | 'blocked' | 'NA';
}

View File

@@ -1,3 +1,5 @@
//
// RULES:
// api method for get notifications by user id
import { pb } from '@/lib/pb';
import { COL_NOTIFICATIONS } from '@/constants';

View File

@@ -0,0 +1,8 @@
import { COL_VOCABULARIES } from '@/constants';
import type { Vocabulary, VocabularyCreate } from './type';
import { pb } from '@/lib/pb';
export default function createVocabulary(data: VocabularyCreate): Promise<Vocabulary> {
return pb.collection(COL_VOCABULARIES).create(data);
}

View File

@@ -0,0 +1,6 @@
import { COL_VOCABULARIES } from '@/constants';
import { pb } from '@/lib/pb';
export default function deleteVocabulary(id: string): Promise<boolean> {
return pb.collection(COL_VOCABULARIES).delete(id);
}

View File

@@ -0,0 +1,8 @@
import { COL_VOCABULARIES } from '@/constants';
import type { Vocabularies } from './type';
import { pb } from '@/lib/pb';
export default function getAllVocabularies(): Promise<Vocabularies> {
return pb.collection(COL_VOCABULARIES).getFullList();
}

View File

@@ -0,0 +1,14 @@
// RULES:
// error handled by caller
// contain definition to collection only
import { COL_VOCABULARIES } from '@/constants';
import { pb } from '@/lib/pb';
export default function getAllVocabulariesCount(): Promise<number> {
return pb
.collection(COL_VOCABULARIES)
.getList(1, 9999)
.then((res) => res.totalItems);
}

View File

@@ -0,0 +1,8 @@
import { COL_VOCABULARIES } from '@/constants';
import type { Vocabulary } from './type';
import { pb } from '@/lib/pb';
export default function getVocabularyById(id: string): Promise<Vocabulary> {
return pb.collection(COL_VOCABULARIES).getOne(id);
}

View File

@@ -0,0 +1,9 @@
import { COL_VOCABULARIES } from '@/constants';
import { pb } from '@/lib/pb';
export default function getHiddenVocabulariesCount(): Promise<number> {
return pb
.collection(COL_VOCABULARIES)
.getList(1, 9999, { filter: 'status = "hidden"' })
.then((res) => res.totalItems);
}

View File

@@ -0,0 +1,9 @@
import { COL_VOCABULARIES } from '@/constants';
import { pb } from '@/lib/pb';
export default function getVisibleVocabulariesCount(): Promise<number> {
return pb
.collection(COL_VOCABULARIES)
.getList(1, 9999, { filter: 'status = "visible"' })
.then((res) => res.totalItems);
}

View File

@@ -0,0 +1,5 @@
function helloWorld(): string {
return 'helloworld';
}
export { helloWorld };

View File

@@ -0,0 +1,8 @@
import { COL_VOCABULARIES } from '@/constants';
import type { RecordModel } from 'pocketbase';
import { pb } from '@/lib/pb';
import type { EditFormProps } from './type';
export default function updateVocabulary(id: string, data: EditFormProps): Promise<RecordModel> {
return pb.collection(COL_VOCABULARIES).update(id, data);
}

View File

@@ -0,0 +1,30 @@
# GUIDELINES
This folder contains drivers for `LessonCategory`/`LessonCategories` records using PocketBase:
- create (Create.tsx)
- read (GetById.tsx)
- write (Update.tsx)
- count (GetAllCount.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 `@/db/LessonCategories/type.d.tsx`
simple template:
```typescript
import { pb } from '@/lib/pb';
import { COL_LESSON_CATEGORIES } from '@/constants';
export async function createLessonCategory(data: CreateFormProps) {
// ...content
// use direct return of pb.collection (e.g. return pb.collection(xxx))
}
```

View File

@@ -0,0 +1,53 @@
// RULES: interface for handling vocabulary record
export interface Vocabulary {
//
id: string;
collectionId: string;
//
word: string;
word_c: string;
sample_e: string;
sample_c: string;
cat_id: string;
category: string;
lesson_type_id: string;
image: File[];
sound: File[];
}
// RULES: interface for handling create form
export interface CreateForm {
word: string;
word_c: string;
sample_e: string;
sample_c: string;
cat_id: string;
category: string;
lesson_type_id: string;
image: File[];
sound: File[];
isActive: boolean;
order: number;
}
// RULES: interface for handling edit form
export interface EditFormProps {
id: string;
collectionId: string;
word: string;
word_c: string;
sample_e: string;
sample_c: string;
cat_id: string;
category: string;
lesson_type_id: string;
image: File[];
sound: File[];
isActive: boolean;
order: number;
}
// RULES: helloworld self test
export interface Helloworld {
helloworld: string;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff