update,
This commit is contained in:
8
002_source/cms/src/db/Vocabularies/Create.tsx
Normal file
8
002_source/cms/src/db/Vocabularies/Create.tsx
Normal 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);
|
||||
}
|
6
002_source/cms/src/db/Vocabularies/Delete.tsx
Normal file
6
002_source/cms/src/db/Vocabularies/Delete.tsx
Normal 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);
|
||||
}
|
8
002_source/cms/src/db/Vocabularies/GetAll.tsx
Normal file
8
002_source/cms/src/db/Vocabularies/GetAll.tsx
Normal 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();
|
||||
}
|
14
002_source/cms/src/db/Vocabularies/GetAllCount.tsx
Normal file
14
002_source/cms/src/db/Vocabularies/GetAllCount.tsx
Normal 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);
|
||||
}
|
8
002_source/cms/src/db/Vocabularies/GetById.tsx
Normal file
8
002_source/cms/src/db/Vocabularies/GetById.tsx
Normal 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);
|
||||
}
|
9
002_source/cms/src/db/Vocabularies/GetHiddenCount.tsx
Normal file
9
002_source/cms/src/db/Vocabularies/GetHiddenCount.tsx
Normal 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);
|
||||
}
|
9
002_source/cms/src/db/Vocabularies/GetVisibleCount.tsx
Normal file
9
002_source/cms/src/db/Vocabularies/GetVisibleCount.tsx
Normal 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);
|
||||
}
|
5
002_source/cms/src/db/Vocabularies/Helloworld.tsx
Normal file
5
002_source/cms/src/db/Vocabularies/Helloworld.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
function helloWorld(): string {
|
||||
return 'helloworld';
|
||||
}
|
||||
|
||||
export { helloWorld };
|
8
002_source/cms/src/db/Vocabularies/Update.tsx
Normal file
8
002_source/cms/src/db/Vocabularies/Update.tsx
Normal 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);
|
||||
}
|
30
002_source/cms/src/db/Vocabularies/_GUIDELINES.md
Normal file
30
002_source/cms/src/db/Vocabularies/_GUIDELINES.md
Normal 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))
|
||||
}
|
||||
```
|
53
002_source/cms/src/db/Vocabularies/type.d.tsx
Normal file
53
002_source/cms/src/db/Vocabularies/type.d.tsx
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user