update
This commit is contained in:
390
scripts/seed-sample-content.js
Normal file
390
scripts/seed-sample-content.js
Normal file
@@ -0,0 +1,390 @@
|
||||
const { sequelize } = require('../config/database');
|
||||
const { Subject, Chapter, Lesson, Game } = require('../models');
|
||||
|
||||
/**
|
||||
* Script để seed sample data cho Content Management System
|
||||
* Tạo môn học, chương, bài học mẫu và game engines
|
||||
*/
|
||||
|
||||
async function seedSampleContent() {
|
||||
try {
|
||||
console.log('🌱 Starting to seed sample content...\n');
|
||||
|
||||
// =====================================
|
||||
// 1. TẠO MÔN HỌC (SUBJECTS)
|
||||
// =====================================
|
||||
console.log('📚 Creating subjects...');
|
||||
|
||||
const mathSubject = await Subject.create({
|
||||
subject_code: 'MATH_G1',
|
||||
subject_name: 'Toán lớp 1',
|
||||
subject_name_en: 'Math Grade 1',
|
||||
description: 'Chương trình Toán học lớp 1 theo SGK mới',
|
||||
is_active: true,
|
||||
is_premium: false,
|
||||
is_public: true,
|
||||
min_subscription_tier: 'basic'
|
||||
});
|
||||
console.log('✅ Created:', mathSubject.subject_name);
|
||||
|
||||
const vietnameseSubject = await Subject.create({
|
||||
subject_code: 'VIET_G1',
|
||||
subject_name: 'Tiếng Việt lớp 1',
|
||||
subject_name_en: 'Vietnamese Grade 1',
|
||||
description: 'Chương trình Tiếng Việt lớp 1',
|
||||
is_active: true,
|
||||
is_premium: false,
|
||||
is_public: true
|
||||
});
|
||||
console.log('✅ Created:', vietnameseSubject.subject_name);
|
||||
|
||||
const englishSubject = await Subject.create({
|
||||
subject_code: 'ENG_G1',
|
||||
subject_name: 'Tiếng Anh lớp 1',
|
||||
subject_name_en: 'English Grade 1',
|
||||
description: 'Chương trình Tiếng Anh cơ bản',
|
||||
is_active: true,
|
||||
is_premium: true,
|
||||
is_public: false,
|
||||
min_subscription_tier: 'premium'
|
||||
});
|
||||
console.log('✅ Created:', englishSubject.subject_name);
|
||||
|
||||
// =====================================
|
||||
// 2. TẠO CHƯƠNG HỌC (CHAPTERS)
|
||||
// =====================================
|
||||
console.log('\n📖 Creating chapters...');
|
||||
|
||||
// Math Chapters
|
||||
const mathChapter1 = await Chapter.create({
|
||||
subject_id: mathSubject.id,
|
||||
chapter_number: 1,
|
||||
chapter_title: 'Số và chữ số',
|
||||
chapter_description: 'Làm quen với các số từ 1 đến 10',
|
||||
duration_minutes: 180,
|
||||
is_published: true,
|
||||
display_order: 1
|
||||
});
|
||||
console.log('✅ Created:', mathChapter1.chapter_title);
|
||||
|
||||
const mathChapter2 = await Chapter.create({
|
||||
subject_id: mathSubject.id,
|
||||
chapter_number: 2,
|
||||
chapter_title: 'Phép cộng trong phạm vi 10',
|
||||
chapter_description: 'Học cộng các số từ 1 đến 10',
|
||||
duration_minutes: 240,
|
||||
is_published: true,
|
||||
display_order: 2
|
||||
});
|
||||
console.log('✅ Created:', mathChapter2.chapter_title);
|
||||
|
||||
// Vietnamese Chapter
|
||||
const vietChapter1 = await Chapter.create({
|
||||
subject_id: vietnameseSubject.id,
|
||||
chapter_number: 1,
|
||||
chapter_title: 'Bảng chữ cái',
|
||||
chapter_description: 'Học bảng chữ cái tiếng Việt',
|
||||
duration_minutes: 300,
|
||||
is_published: true,
|
||||
display_order: 1
|
||||
});
|
||||
console.log('✅ Created:', vietChapter1.chapter_title);
|
||||
|
||||
// =====================================
|
||||
// 3. TẠO GAME ENGINES
|
||||
// =====================================
|
||||
console.log('\n🎮 Creating game engines...');
|
||||
|
||||
const countingGame = await Game.create({
|
||||
title: 'Trò chơi đếm số',
|
||||
description: 'Game tương tác giúp trẻ học đếm các vật thể',
|
||||
url: 'https://games.senaai.tech/counting-game/index.html',
|
||||
thumbnail: 'https://cdn.senaai.tech/game-thumbs/counting.jpg',
|
||||
type: 'counting_quiz',
|
||||
config: {
|
||||
engine: 'phaser3',
|
||||
version: '1.0.0',
|
||||
features: ['sound', 'animation', 'reward_stars'],
|
||||
controls: ['touch', 'mouse', 'keyboard']
|
||||
},
|
||||
is_active: true,
|
||||
is_premium: false,
|
||||
min_grade: 1,
|
||||
max_grade: 2,
|
||||
difficulty_level: 'easy',
|
||||
display_order: 1
|
||||
});
|
||||
console.log('✅ Created:', countingGame.title);
|
||||
|
||||
const quizGame = await Game.create({
|
||||
title: 'Trả lời nhanh',
|
||||
description: 'Trò chơi trắc nghiệm với giới hạn thời gian',
|
||||
url: 'https://games.senaai.tech/quiz-game/index.html',
|
||||
thumbnail: 'https://cdn.senaai.tech/game-thumbs/quiz.jpg',
|
||||
type: 'multiple_choice_quiz',
|
||||
config: {
|
||||
engine: 'react',
|
||||
features: ['timer', 'leaderboard', 'achievements']
|
||||
},
|
||||
is_active: true,
|
||||
is_premium: false,
|
||||
min_grade: 1,
|
||||
max_grade: 12,
|
||||
difficulty_level: 'medium',
|
||||
display_order: 2
|
||||
});
|
||||
console.log('✅ Created:', quizGame.title);
|
||||
|
||||
const mathPracticeGame = await Game.create({
|
||||
title: 'Luyện tập Toán',
|
||||
description: 'Game luyện toán với nhiều cấp độ khó',
|
||||
url: 'https://games.senaai.tech/math-practice/index.html',
|
||||
thumbnail: 'https://cdn.senaai.tech/game-thumbs/math.jpg',
|
||||
type: 'math_practice',
|
||||
config: {
|
||||
engine: 'unity_webgl',
|
||||
features: ['adaptive_difficulty', 'step_by_step_solution']
|
||||
},
|
||||
is_active: true,
|
||||
is_premium: true,
|
||||
min_grade: 1,
|
||||
max_grade: 6,
|
||||
difficulty_level: 'medium',
|
||||
display_order: 3
|
||||
});
|
||||
console.log('✅ Created:', mathPracticeGame.title);
|
||||
|
||||
// =====================================
|
||||
// 4. TẠO BÀI HỌC (LESSONS)
|
||||
// =====================================
|
||||
console.log('\n📝 Creating lessons...');
|
||||
|
||||
// Lesson 1: Simple counting quiz
|
||||
const lesson1 = await Lesson.create({
|
||||
chapter_id: mathChapter1.id,
|
||||
lesson_number: 1,
|
||||
lesson_title: 'Đếm từ 1 đến 5',
|
||||
lesson_type: 'json_content',
|
||||
lesson_description: 'Học đếm các số từ 1 đến 5 qua trò chơi',
|
||||
content_json: {
|
||||
type: 'counting_quiz',
|
||||
theme: 'fruits',
|
||||
questions: [
|
||||
{
|
||||
id: 1,
|
||||
question: 'Có bao nhiêu quả táo?',
|
||||
image: 'https://cdn.senaai.tech/images/apples-3.png',
|
||||
correct_answer: 3,
|
||||
options: [2, 3, 4, 5]
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
question: 'Có bao nhiêu quả cam?',
|
||||
image: 'https://cdn.senaai.tech/images/oranges-5.png',
|
||||
correct_answer: 5,
|
||||
options: [3, 4, 5, 6]
|
||||
}
|
||||
],
|
||||
instructions: 'Nhìn vào hình và đếm số lượng vật',
|
||||
pass_score: 70
|
||||
},
|
||||
duration_minutes: 15,
|
||||
is_published: true,
|
||||
is_free: true,
|
||||
display_order: 1
|
||||
});
|
||||
console.log('✅ Created:', lesson1.lesson_title);
|
||||
|
||||
// Lesson 2: Video lesson
|
||||
const lesson2 = await Lesson.create({
|
||||
chapter_id: mathChapter1.id,
|
||||
lesson_number: 2,
|
||||
lesson_title: 'Video: Hướng dẫn đếm số',
|
||||
lesson_type: 'url_content',
|
||||
lesson_description: 'Video hướng dẫn cách đếm số từ 1 đến 10',
|
||||
content_url: 'https://www.youtube.com/watch?v=demo123',
|
||||
content_type: 'youtube',
|
||||
duration_minutes: 10,
|
||||
is_published: true,
|
||||
is_free: false,
|
||||
display_order: 2
|
||||
});
|
||||
console.log('✅ Created:', lesson2.lesson_title);
|
||||
|
||||
// Lesson 3: Composite lesson with multiple components
|
||||
const lesson3 = await Lesson.create({
|
||||
chapter_id: mathChapter1.id,
|
||||
lesson_number: 3,
|
||||
lesson_title: 'Bài học tổng hợp: Đếm và so sánh',
|
||||
lesson_type: 'json_content',
|
||||
lesson_description: 'Bài học tích hợp nhiều hoạt động',
|
||||
content_json: {
|
||||
type: 'composite_lesson',
|
||||
version: '2.0',
|
||||
layout: 'vertical',
|
||||
components: [
|
||||
{
|
||||
id: 'story-1',
|
||||
type: 'story_game',
|
||||
order: 1,
|
||||
title: 'Câu chuyện: Gấu đếm táo',
|
||||
config: {
|
||||
skippable: true,
|
||||
auto_play: false
|
||||
},
|
||||
content: {
|
||||
scenes: [
|
||||
{
|
||||
scene_id: 1,
|
||||
background: 'https://cdn.senaai.tech/scenes/forest.jpg',
|
||||
character: 'bear',
|
||||
dialogue: 'Chào các em! Hôm nay chú gấu sẽ dạy các em đếm.',
|
||||
duration: 5
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'game-1',
|
||||
type: 'game',
|
||||
order: 2,
|
||||
title: 'Trò chơi đếm số',
|
||||
required: true,
|
||||
unlock_after: 'story-1',
|
||||
config: {
|
||||
game_type: 'counting_quiz',
|
||||
difficulty: 'medium'
|
||||
},
|
||||
content: {
|
||||
questions: [
|
||||
{
|
||||
id: 1,
|
||||
question: 'Đếm số con vịt',
|
||||
image: 'https://cdn.senaai.tech/images/ducks-7.png',
|
||||
correct_answer: 7,
|
||||
options: [5, 6, 7, 8]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'results-1',
|
||||
type: 'results_board',
|
||||
order: 3,
|
||||
title: 'Kết quả',
|
||||
unlock_after: 'game-1',
|
||||
content: {
|
||||
display_fields: [
|
||||
{ field: 'score', label: 'Điểm số', format: 'number' },
|
||||
{ field: 'accuracy', label: 'Độ chính xác', format: 'percentage' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'leaderboard-1',
|
||||
type: 'leaderboard',
|
||||
order: 4,
|
||||
title: 'Bảng xếp hạng',
|
||||
config: {
|
||||
scope: 'class',
|
||||
time_range: 'week'
|
||||
}
|
||||
}
|
||||
],
|
||||
global_config: {
|
||||
enable_navigation: true,
|
||||
allow_skip: false
|
||||
}
|
||||
},
|
||||
duration_minutes: 25,
|
||||
is_published: true,
|
||||
is_free: false,
|
||||
display_order: 3
|
||||
});
|
||||
console.log('✅ Created:', lesson3.lesson_title);
|
||||
|
||||
// Lesson 4: Math practice
|
||||
const lesson4 = await Lesson.create({
|
||||
chapter_id: mathChapter2.id,
|
||||
lesson_number: 1,
|
||||
lesson_title: 'Luyện tập phép cộng',
|
||||
lesson_type: 'json_content',
|
||||
content_json: {
|
||||
type: 'math_practice',
|
||||
difficulty: 'easy',
|
||||
operations: ['addition'],
|
||||
range: { min: 1, max: 10 },
|
||||
question_count: 20,
|
||||
show_solution_steps: true
|
||||
},
|
||||
duration_minutes: 20,
|
||||
is_published: true,
|
||||
display_order: 1
|
||||
});
|
||||
console.log('✅ Created:', lesson4.lesson_title);
|
||||
|
||||
// Lesson 5: Vietnamese alphabet
|
||||
const lesson5 = await Lesson.create({
|
||||
chapter_id: vietChapter1.id,
|
||||
lesson_number: 1,
|
||||
lesson_title: 'Học bảng chữ cái A-Z',
|
||||
lesson_type: 'json_content',
|
||||
content_json: {
|
||||
type: 'word_puzzle',
|
||||
letters: ['A', 'B', 'C', 'D', 'E'],
|
||||
exercises: [
|
||||
{
|
||||
letter: 'A',
|
||||
pronunciation: 'a',
|
||||
examples: ['Áo', 'Ăn', 'An']
|
||||
}
|
||||
]
|
||||
},
|
||||
duration_minutes: 30,
|
||||
is_published: true,
|
||||
is_free: true,
|
||||
display_order: 1
|
||||
});
|
||||
console.log('✅ Created:', lesson5.lesson_title);
|
||||
|
||||
// =====================================
|
||||
// SUMMARY
|
||||
// =====================================
|
||||
console.log('\n🎉 Sample content seeding completed!');
|
||||
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
||||
console.log('📊 Summary:');
|
||||
console.log(` • Subjects: 3`);
|
||||
console.log(` • Chapters: 3`);
|
||||
console.log(` • Lessons: 5`);
|
||||
console.log(` • Games: 3`);
|
||||
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');
|
||||
|
||||
console.log('✅ You can now:');
|
||||
console.log(' 1. GET /api/subjects - View all subjects');
|
||||
console.log(' 2. GET /api/subjects/:id/chapters - View chapters');
|
||||
console.log(' 3. GET /api/chapters/:id/lessons - View lessons');
|
||||
console.log(' 4. GET /api/lessons/:id - View lesson detail');
|
||||
console.log(' 5. GET /api/games?type=counting_quiz - Find matching games\n');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Error seeding data:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Run the seeder
|
||||
if (require.main === module) {
|
||||
seedSampleContent()
|
||||
.then(() => {
|
||||
console.log('✅ Script completed successfully');
|
||||
process.exit(0);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('❌ Script failed:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = seedSampleContent;
|
||||
Reference in New Issue
Block a user