add changes

This commit is contained in:
AD2025
2025-11-11 00:25:50 +02:00
commit e3ca132c5e
86 changed files with 22238 additions and 0 deletions

239
backend/SEEDING.md Normal file
View File

@@ -0,0 +1,239 @@
# Database Seeding
This document describes the demo data seeded into the database for development and testing purposes.
## Overview
The database includes 4 seeders that populate initial data:
1. **Categories Seeder** - 7 technical topic categories
2. **Admin User Seeder** - 1 admin account for management
3. **Questions Seeder** - 35 demo questions (5 per category)
4. **Achievements Seeder** - 19 gamification achievements
## Running Seeders
### Seed all data
```bash
npm run seed
# or
npx sequelize-cli db:seed:all
```
### Undo all seeders
```bash
npm run seed:undo
# or
npx sequelize-cli db:seed:undo:all
```
### Reseed (undo + seed)
```bash
npm run seed:undo && npm run seed
```
## Seeded Data Details
### 1. Categories (7 total)
| Category | Slug | Guest Accessible | Display Order | Icon |
|----------|------|------------------|---------------|------|
| JavaScript | `javascript` | ✅ Yes | 1 | 🟨 |
| Angular | `angular` | ✅ Yes | 2 | 🅰️ |
| React | `react` | ✅ Yes | 3 | ⚛️ |
| Node.js | `nodejs` | ❌ Auth Required | 4 | 🟢 |
| TypeScript | `typescript` | ❌ Auth Required | 5 | 📘 |
| SQL & Databases | `sql-databases` | ❌ Auth Required | 6 | 🗄️ |
| System Design | `system-design` | ❌ Auth Required | 7 | 🏗️ |
**Guest vs. Auth:**
- **Guest-accessible** (3): JavaScript, Angular, React - Users can take quizzes without authentication
- **Auth-required** (4): Node.js, TypeScript, SQL & Databases, System Design - Must be logged in
### 2. Admin User (1 total)
**Credentials:**
- **Email:** `admin@quiz.com`
- **Password:** `Admin@123`
- **Username:** `admin`
- **Role:** `admin`
**Use Cases:**
- Test admin authentication
- Create/edit questions
- Manage categories
- View analytics
- Test admin-only features
### 3. Questions (35 total)
#### Distribution by Category:
- **JavaScript**: 5 questions
- **Angular**: 5 questions
- **React**: 5 questions
- **Node.js**: 5 questions
- **TypeScript**: 5 questions
- **SQL & Databases**: 5 questions
- **System Design**: 5 questions
#### By Difficulty:
- **Easy**: 15 questions (5 points, 60 seconds)
- **Medium**: 15 questions (10 points, 90 seconds)
- **Hard**: 5 questions (15 points, 120 seconds)
#### Question Types:
- **Multiple Choice**: All 35 questions
- **True/False**: 0 questions (can be added later)
- **Written**: 0 questions (can be added later)
#### Sample Questions:
**JavaScript:**
1. What is the difference between let and var? (Easy)
2. What is a closure in JavaScript? (Medium)
3. What does the spread operator (...) do? (Easy)
4. What is the purpose of Promise.all()? (Medium)
5. What is event delegation? (Medium)
**Angular:**
1. What is the purpose of NgModule? (Easy)
2. What is dependency injection? (Medium)
3. What is the difference between @Input() and @Output()? (Easy)
4. What is RxJS used for? (Medium)
5. What is the purpose of Angular lifecycle hooks? (Easy)
**React:**
1. What is the virtual DOM? (Easy)
2. What is the purpose of useEffect hook? (Easy)
3. What is prop drilling? (Medium)
4. What is the difference between useMemo and useCallback? (Medium)
5. What is React Context API used for? (Easy)
**Node.js:**
1. What is the event loop? (Medium)
2. What is middleware in Express.js? (Easy)
3. What is the purpose of package.json? (Easy)
4. What is the difference between process.nextTick() and setImmediate()? (Hard)
5. What is clustering in Node.js? (Medium)
**TypeScript:**
1. What is the difference between interface and type? (Medium)
2. What is a generic? (Medium)
3. What is the "never" type? (Hard)
4. What is type narrowing? (Medium)
5. What is the purpose of the "readonly" modifier? (Easy)
**SQL & Databases:**
1. What is the difference between INNER JOIN and LEFT JOIN? (Easy)
2. What is database normalization? (Medium)
3. What is an index in a database? (Easy)
4. What is a transaction in SQL? (Medium)
5. What does the GROUP BY clause do? (Easy)
**System Design:**
1. What is horizontal scaling vs vertical scaling? (Easy)
2. What is a load balancer? (Easy)
3. What is CAP theorem? (Medium)
4. What is caching and why is it used? (Easy)
5. What is a microservices architecture? (Medium)
### 4. Achievements (19 total)
#### By Category:
**Milestone (4):**
- 🎯 **First Steps** - Complete your very first quiz (10 pts)
- 📚 **Quiz Enthusiast** - Complete 10 quizzes (50 pts)
- 🏆 **Quiz Master** - Complete 50 quizzes (250 pts)
- 👑 **Quiz Legend** - Complete 100 quizzes (500 pts)
**Score (3):**
- 💯 **Perfect Score** - Achieve 100% on any quiz (100 pts)
-**Perfectionist** - Achieve 100% on 5 quizzes (300 pts)
- 🎓 **High Achiever** - Maintain 80% average across all quizzes (200 pts)
**Speed (2):**
-**Speed Demon** - Complete a quiz in under 2 minutes (75 pts)
- 🚀 **Lightning Fast** - Complete 10 quizzes in under 2 minutes each (200 pts)
**Streak (3):**
- 🔥 **On a Roll** - Maintain a 3-day streak (50 pts)
- 🔥🔥 **Week Warrior** - Maintain a 7-day streak (150 pts)
- 🔥🔥🔥 **Month Champion** - Maintain a 30-day streak (500 pts)
**Quiz (3):**
- 🗺️ **Explorer** - Complete quizzes in 3 different categories (100 pts)
- 🌟 **Jack of All Trades** - Complete quizzes in 5 different categories (200 pts)
- 🌈 **Master of All** - Complete quizzes in all 7 categories (400 pts)
**Special (4):**
- 🌅 **Early Bird** - Complete a quiz before 8 AM (50 pts)
- 🦉 **Night Owl** - Complete a quiz after 10 PM (50 pts)
- 🎉 **Weekend Warrior** - Complete 10 quizzes on weekends (100 pts)
- 💪 **Comeback King** - Score 90%+ after scoring below 50% (150 pts)
#### Achievement Requirements:
Achievement unlocking is tracked via the `requirement_type` field:
- `quizzes_completed` - Based on total quizzes completed
- `quizzes_passed` - Based on quizzes passed (e.g., 80% average)
- `perfect_score` - Based on number of 100% scores
- `streak_days` - Based on consecutive days streak
- `category_master` - Based on number of different categories completed
- `speed_demon` - Based on quiz completion time
- `early_bird` - Based on time of day (also used for Night Owl, Weekend Warrior, Comeback King)
## Verification
To verify seeded data, run:
```bash
node verify-seeded-data.js
```
This will output:
- Row counts for each table
- List of all categories
- Admin user credentials
- Questions count by category
- Achievements count by category
## Data Integrity
All seeded data maintains proper relationships:
1. **Questions → Categories**
- Each question has a valid `category_id` foreign key
- Category slugs are used to find category IDs during seeding
2. **Questions → Users**
- All questions have `created_by` set to admin user ID
- Admin user is seeded before questions
3. **Categories**
- Each has a unique slug for URL routing
- Display order ensures consistent sorting
4. **Achievements**
- All have valid category ENUM values
- All have valid requirement_type ENUM values
## Notes
- All timestamps are set to the same time during seeding for consistency
- All UUIDs are regenerated on each seed run
- Guest-accessible categories allow unauthenticated quiz taking
- Auth-required categories need user authentication
- Questions include explanations for learning purposes
- All questions are multiple-choice with 4 options
- Correct answers are stored as JSON arrays (supports multiple correct answers)
## Future Enhancements
Consider adding:
- More questions per category (currently 5)
- True/False question types
- Written answer question types
- Guest settings seeder
- Sample user accounts (non-admin)
- Quiz session history
- User achievement completions