TransHub_backend / seed-data.js
linguabot's picture
Upload folder using huggingface_hub
da819ac verified
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('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);
// Tutorial Tasks for Week 1
console.log('Creating tutorial tasks...');
const tutorialTasks = [
{
title: 'Cultural Adaptation Exercise',
content: 'Translate the following marketing slogan for a Western audience: "Our product brings harmony to your life." Consider cultural differences in how harmony is perceived.',
sourceLanguage: 'English',
targetLanguage: 'English',
category: 'tutorial',
weekNumber: 1,
translationBrief: 'Adapt this slogan for a Western audience, focusing on individualism and personal achievement rather than collective harmony.',
isActive: true
},
{
title: 'Localization Challenge',
content: 'Adapt this restaurant menu item: "Spicy Dragon Noodles" for a conservative American audience.',
sourceLanguage: 'English',
targetLanguage: 'English',
category: 'tutorial',
weekNumber: 1,
translationBrief: 'Make this dish more appealing to conservative American diners who might be unfamiliar with Asian cuisine.',
isActive: true
},
{
title: 'Brand Voice Translation',
content: 'Translate this luxury brand tagline: "Excellence in every detail" for a younger, more casual audience.',
sourceLanguage: 'English',
targetLanguage: 'English',
category: 'tutorial',
weekNumber: 1,
translationBrief: 'Maintain the premium feel while making it more accessible and relatable to younger consumers.',
isActive: true
}
];
for (const task of tutorialTasks) {
await SourceText.findOneAndUpdate(
{ title: task.title, category: 'tutorial', weekNumber: task.weekNumber },
task,
{ upsert: true, new: true }
);
}
console.log('Tutorial tasks created for Week 1');
// Weekly Practice Tasks for all weeks
console.log('Creating weekly practice tasks...');
const weeklyPracticeTasks = [
{
title: 'Week 1 Practice: Cultural Nuances',
content: 'Translate this greeting: "How are you?" for different cultural contexts. Consider formality levels and cultural expectations.',
sourceLanguage: 'English',
targetLanguage: 'English',
category: 'weekly-practice',
weekNumber: 1,
translationBrief: 'Adapt this greeting for formal business settings, casual social situations, and family contexts.',
isActive: true
},
{
title: 'Week 2 Practice: Marketing Adaptation',
content: 'Adapt this product description: "Revolutionary technology that changes everything" for a skeptical audience.',
sourceLanguage: 'English',
targetLanguage: 'English',
category: 'weekly-practice',
weekNumber: 2,
translationBrief: 'Make this claim more credible and less hyperbolic for a skeptical, evidence-based audience.',
isActive: true
},
{
title: 'Week 3 Practice: Emotional Translation',
content: 'Translate this emotional expression: "I am so happy" for different cultural contexts where emotional expression varies.',
sourceLanguage: 'English',
targetLanguage: 'English',
category: 'weekly-practice',
weekNumber: 3,
translationBrief: 'Adapt this expression for cultures that value emotional restraint and those that encourage emotional expression.',
isActive: true
},
{
title: 'Week 4 Practice: Humor Translation',
content: 'Adapt this joke: "Why did the chicken cross the road? To get to the other side!" for a culture that doesn\'t have this idiom.',
sourceLanguage: 'English',
targetLanguage: 'English',
category: 'weekly-practice',
weekNumber: 4,
translationBrief: 'Create a culturally appropriate version that maintains the humor while being accessible to the target culture.',
isActive: true
},
{
title: 'Week 5 Practice: Formal vs Informal',
content: 'Translate this business communication: "We would appreciate your prompt response" for different formality levels.',
sourceLanguage: 'English',
targetLanguage: 'English',
category: 'weekly-practice',
weekNumber: 5,
translationBrief: 'Create versions for very formal, moderately formal, and casual business contexts.',
isActive: true
},
{
title: 'Week 6 Practice: Cultural Values',
content: 'Adapt this value statement: "Success comes from hard work" for cultures with different views on success and work.',
sourceLanguage: 'English',
targetLanguage: 'English',
category: 'weekly-practice',
weekNumber: 6,
translationBrief: 'Consider cultures that value collaboration over individual achievement, and those that emphasize luck or fate.',
isActive: true
}
];
for (const task of weeklyPracticeTasks) {
await SourceText.findOneAndUpdate(
{ title: task.title, category: 'weekly-practice', weekNumber: task.weekNumber },
task,
{ upsert: true, new: true }
);
}
console.log('Weekly practice tasks created for all weeks');
console.log('Database seeding completed successfully!');
console.log('');
console.log('Test Accounts:');
console.log('Admin: admin@example.com / admin123');
console.log('Student: student@example.com / student123');
console.log('');
console.log('You can now log in and see the tutorial tasks and weekly practice content.');
} catch (error) {
console.error('Error seeding database:', error);
} finally {
await mongoose.disconnect();
console.log('Disconnected from MongoDB');
}
}
// Run the seeding function
seedDatabase();