Spaces:
Sleeping
Sleeping
| const mongoose = require('mongoose'); | |
| const bcrypt = require('bcryptjs'); | |
| const User = require('./models/User'); | |
| const SourceText = require('./models/SourceText'); | |
| // MongoDB connection | |
| const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017/transcreation-sandbox'; | |
| async function seedDatabase() { | |
| try { | |
| console.log('🌱 Starting database seeding...'); | |
| console.log('Connecting to MongoDB...'); | |
| await mongoose.connect(MONGODB_URI); | |
| console.log('✅ Connected to MongoDB'); | |
| // Create admin user | |
| console.log('👤 Creating admin user...'); | |
| const adminPassword = await bcrypt.hash('admin123', 10); | |
| const adminUser = await User.findOneAndUpdate( | |
| { email: 'admin@example.com' }, | |
| { | |
| email: 'admin@example.com', | |
| password: adminPassword, | |
| username: 'admin', | |
| role: 'admin', | |
| isActive: true | |
| }, | |
| { upsert: true, new: true } | |
| ); | |
| console.log('✅ Admin user created:', adminUser.email); | |
| // Create student user | |
| console.log('👤 Creating student user...'); | |
| const studentPassword = await bcrypt.hash('student123', 10); | |
| const studentUser = await User.findOneAndUpdate( | |
| { email: 'student@example.com' }, | |
| { | |
| email: 'student@example.com', | |
| password: studentPassword, | |
| username: 'student', | |
| role: 'student', | |
| isActive: true | |
| }, | |
| { upsert: true, new: true } | |
| ); | |
| console.log('✅ Student user created:', studentUser.email); | |
| // Clear existing source texts | |
| console.log('🗑️ Clearing existing source texts...'); | |
| await SourceText.deleteMany({}); | |
| console.log('✅ Cleared existing source texts'); | |
| // Create tutorial tasks for Week 1 | |
| console.log('📚 Creating tutorial tasks for Week 1...'); | |
| const tutorialTasks = [ | |
| { | |
| title: 'Tutorial Task 1', | |
| content: 'The early bird catches the worm.', | |
| category: 'tutorial', | |
| weekNumber: 1, | |
| sourceLanguage: 'English', | |
| sourceCulture: 'Western', | |
| difficulty: 'beginner', | |
| translationBrief: 'Translate this proverb into Chinese, maintaining its cultural meaning.' | |
| }, | |
| { | |
| title: 'Tutorial Task 2', | |
| content: 'Actions speak louder than words.', | |
| category: 'tutorial', | |
| weekNumber: 1, | |
| sourceLanguage: 'English', | |
| sourceCulture: 'Western', | |
| difficulty: 'beginner', | |
| translationBrief: 'Translate this saying into Chinese, preserving its idiomatic nature.' | |
| }, | |
| { | |
| title: 'Tutorial Task 3', | |
| content: 'A picture is worth a thousand words.', | |
| category: 'tutorial', | |
| weekNumber: 1, | |
| sourceLanguage: 'English', | |
| sourceCulture: 'Western', | |
| difficulty: 'beginner', | |
| translationBrief: 'Translate this expression into Chinese, keeping its metaphorical meaning.' | |
| } | |
| ]; | |
| for (const task of tutorialTasks) { | |
| await SourceText.create(task); | |
| } | |
| console.log('✅ Created', tutorialTasks.length, 'tutorial tasks'); | |
| // Create tutorial tasks for Week 2 (with images) | |
| console.log('📚 Creating tutorial tasks for Week 2...'); | |
| const tutorialTasksWeek2 = [ | |
| { | |
| title: 'Tutorial Task 1 - Week 2', | |
| content: 'A picture is worth a thousand words.', | |
| category: 'tutorial', | |
| weekNumber: 2, | |
| sourceLanguage: 'English', | |
| sourceCulture: 'Western', | |
| difficulty: 'intermediate', | |
| translationBrief: 'Translate this saying into Chinese, considering the visual context of the image.', | |
| imageUrl: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=800&h=600&fit=crop', | |
| imageAlt: 'A beautiful landscape photograph showing mountains and lake' | |
| }, | |
| { | |
| title: 'Tutorial Task 2 - Week 2', | |
| content: 'The early bird catches the worm.', | |
| category: 'tutorial', | |
| weekNumber: 2, | |
| sourceLanguage: 'English', | |
| sourceCulture: 'Western', | |
| difficulty: 'intermediate', | |
| translationBrief: 'Translate this proverb into Chinese, considering the visual elements in the image.', | |
| imageUrl: 'https://images.unsplash.com/photo-1444464666168-49d633b86797?w=800&h=600&fit=crop', | |
| imageAlt: 'A bird perched on a branch during sunrise' | |
| }, | |
| { | |
| title: 'Tutorial Task 3 - Week 2', | |
| content: 'Actions speak louder than words.', | |
| category: 'tutorial', | |
| weekNumber: 2, | |
| sourceLanguage: 'English', | |
| sourceCulture: 'Western', | |
| difficulty: 'intermediate', | |
| translationBrief: 'Translate this saying into Chinese, considering the visual context provided.', | |
| imageUrl: 'https://images.unsplash.com/photo-1557804506-669a67965ba0?w=800&h=600&fit=crop', | |
| imageAlt: 'People working together in a collaborative environment' | |
| } | |
| ]; | |
| for (const task of tutorialTasksWeek2) { | |
| await SourceText.create(task); | |
| } | |
| console.log('✅ Created', tutorialTasksWeek2.length, 'tutorial tasks for Week 2'); | |
| // Create weekly practice tasks for Week 1 | |
| console.log('📝 Creating weekly practice tasks for Week 1...'); | |
| const weeklyPracticeTasks = [ | |
| { | |
| title: 'Week 1 Practice 1', | |
| content: '为什么睡前一定要吃夜宵?因为这样才不会做饿梦。', | |
| category: 'weekly-practice', | |
| weekNumber: 1, | |
| sourceLanguage: 'Chinese', | |
| sourceCulture: 'Chinese', | |
| difficulty: 'intermediate', | |
| translationBrief: 'Translate this humorous Chinese text into English, maintaining its wordplay and cultural humor.' | |
| }, | |
| { | |
| title: 'Week 1 Practice 2', | |
| content: '女娲用什么补天?强扭的瓜。', | |
| category: 'weekly-practice', | |
| weekNumber: 1, | |
| sourceLanguage: 'Chinese', | |
| sourceCulture: 'Chinese', | |
| difficulty: 'intermediate', | |
| translationBrief: 'Translate this Chinese riddle into English, preserving its clever wordplay.' | |
| }, | |
| { | |
| title: 'Week 1 Practice 3', | |
| content: '你知道如何区分真假大象吗?把他们仍进水中,真相会浮出水面的。', | |
| category: 'weekly-practice', | |
| weekNumber: 1, | |
| sourceLanguage: 'Chinese', | |
| sourceCulture: 'Chinese', | |
| difficulty: 'intermediate', | |
| translationBrief: 'Translate this Chinese joke into English, maintaining its pun and humor.' | |
| }, | |
| { | |
| title: 'Week 1 Practice 4', | |
| content: 'What if Soy milk is just regular milk introducing itself in Spanish.', | |
| category: 'weekly-practice', | |
| weekNumber: 1, | |
| sourceLanguage: 'English', | |
| sourceCulture: 'Western', | |
| difficulty: 'intermediate', | |
| translationBrief: 'Translate this English joke into Chinese, preserving its linguistic humor.' | |
| }, | |
| { | |
| title: 'Week 1 Practice 5', | |
| content: 'I can\'t believe I got fired from the calendar factory. All I did was take a day off.', | |
| category: 'weekly-practice', | |
| weekNumber: 1, | |
| sourceLanguage: 'English', | |
| sourceCulture: 'Western', | |
| difficulty: 'intermediate', | |
| translationBrief: 'Translate this English joke into Chinese, maintaining its wordplay humor.' | |
| }, | |
| { | |
| title: 'Week 1 Practice 6', | |
| content: 'When life gives you melons, you might be dyslexic.', | |
| category: 'weekly-practice', | |
| weekNumber: 1, | |
| sourceLanguage: 'English', | |
| sourceCulture: 'Western', | |
| difficulty: 'intermediate', | |
| translationBrief: 'Translate this English wordplay into Chinese, preserving its linguistic cleverness.' | |
| } | |
| ]; | |
| for (const task of weeklyPracticeTasks) { | |
| await SourceText.create(task); | |
| } | |
| console.log('✅ Created', weeklyPracticeTasks.length, 'weekly practice tasks'); | |
| // Create practice examples (legacy support) | |
| console.log('📖 Creating practice examples...'); | |
| const practiceExamples = [ | |
| { | |
| title: 'Practice Example 1', | |
| content: '为什么睡前一定要吃夜宵?因为这样才不会做饿梦。', | |
| category: 'weekly-practice', | |
| weekNumber: 1, | |
| sourceLanguage: 'Chinese', | |
| sourceCulture: 'Chinese', | |
| difficulty: 'intermediate' | |
| }, | |
| { | |
| title: 'Practice Example 2', | |
| content: '女娲用什么补天?强扭的瓜。', | |
| category: 'weekly-practice', | |
| weekNumber: 1, | |
| sourceLanguage: 'Chinese', | |
| sourceCulture: 'Chinese', | |
| difficulty: 'intermediate' | |
| }, | |
| { | |
| title: 'Practice Example 3', | |
| content: '你知道如何区分真假大象吗?把他们仍进水中,真相会浮出水面的。', | |
| category: 'weekly-practice', | |
| weekNumber: 1, | |
| sourceLanguage: 'Chinese', | |
| sourceCulture: 'Chinese', | |
| difficulty: 'intermediate' | |
| }, | |
| { | |
| title: 'Practice Example 4', | |
| content: 'What if Soy milk is just regular milk introducing itself in Spanish.', | |
| category: 'weekly-practice', | |
| weekNumber: 1, | |
| sourceLanguage: 'English', | |
| sourceCulture: 'Western', | |
| difficulty: 'intermediate' | |
| } | |
| ]; | |
| for (const example of practiceExamples) { | |
| await SourceText.create(example); | |
| } | |
| console.log('✅ Created', practiceExamples.length, 'practice examples'); | |
| console.log('🎉 Database seeding completed successfully!'); | |
| console.log(''); | |
| console.log('📋 Created:'); | |
| console.log(' 👤 Admin user: admin@example.com / admin123'); | |
| console.log(' 👤 Student user: student@example.com / student123'); | |
| console.log(' 📚 Tutorial tasks: 3 tasks for Week 1'); | |
| console.log(' 📝 Weekly practice: 6 tasks for Week 1'); | |
| console.log(' 📖 Practice examples: 4 examples'); | |
| console.log(''); | |
| console.log('🔗 You can now:'); | |
| console.log(' 1. Log in with admin@example.com / admin123'); | |
| console.log(' 2. Log in with student@example.com / student123'); | |
| console.log(' 3. View tutorial tasks and weekly practice'); | |
| console.log(' 4. Create submissions and test the voting system'); | |
| } catch (error) { | |
| console.error('❌ Database seeding failed:', error); | |
| process.exit(1); | |
| } finally { | |
| await mongoose.disconnect(); | |
| console.log('🔌 Disconnected from MongoDB'); | |
| } | |
| } | |
| // Run the seeding | |
| seedDatabase(); |