This commit is contained in:
louiscklaw
2025-05-08 14:38:34 +08:00
parent 61c10821b6
commit 7105bc85e3
57 changed files with 2973 additions and 5129 deletions

View File

@@ -1,6 +1,8 @@
# GUIDELINES
This folder contains drivers for `QuizLPQuestion` records using PocketBase:
This folder contains drivers for `QuizLPQuestion`/`QuizLPQuestions` records using PocketBase:
## File Structure
- create (Create.tsx)
- read (GetById.tsx)
@@ -8,27 +10,72 @@ This folder contains drivers for `QuizLPQuestion` records using PocketBase:
- count (GetAllCount.tsx)
- delete (Delete.tsx)
- list (GetAll.tsx)
- validation (validateQuestion.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/QuizLPQuestions/type.d.tsx`
- Quiz LP questions require special handling for:
- Answer validation
- Question type checking
- Category association
simple template:
## Complete Implementation Template
```typescript
import { pb } from '@/lib/pb';
import { COL_QUIZ_LP_QUESTIONS } from '@/constants';
import type { QuizLPQuestion, CreateFormProps } from './type.d.ts';
export async function createQuizLPQuestion(data: CreateFormProps) {
// ...content
// use direct return of pb.collection (e.g. return pb.collection(COL_QUIZ_LP_QUESTIONS))
export async function createQuizLPQuestion(data: CreateFormProps): Promise<QuizLPQuestion> {
return pb.collection(COL_QUIZ_LP_QUESTIONS).create(data);
}
```
## Question-Specific Handling
### Answer Validation
```typescript
export function validateLPQuestionAnswer(question: QuizLPQuestion, answer: string): boolean {
// Implement LP question specific validation
return question.correctAnswer === answer;
}
```
### Type Definitions
```typescript
interface QuizLPQuestion {
id: string;
question: string;
options: string[];
correctAnswer: string;
categoryId: string;
difficulty: 'easy'|'medium'|'hard';
}
```
## Common Patterns
```typescript
// Get questions by category
export async function getQuestionsByCategory(categoryId: string) {
return pb.collection(COL_QUIZ_LP_QUESTIONS)
.getFullList({ filter: `categoryId = "${categoryId}"` });
}
// Validate before create
export async function createValidatedQuestion(data: CreateFormProps) {
if (!validateQuestionData(data)) throw new Error('Invalid question data');
return createQuizLPQuestion(data);
}
```
## Performance Considerations
- Add index on: categoryId, difficulty
- Consider pagination for large question sets
- Cache frequently accessed questions
## Testing Guidelines
Recommended test cases:
- Basic CRUD operations
- Answer validation
- Category filtering
- Difficulty level queries
- Error cases (invalid data)