refactor: improve service layer logging and configuration
- Change email service logging from console.log to console.warn for better visibility - Update mailgun and couchdb configuration with improved error handling - Enhance database seeder with better logging and error management - Improve service factory patterns for better testability
This commit is contained in:
@@ -10,23 +10,23 @@ export class DatabaseSeeder {
|
||||
const adminEmail = 'admin@localhost';
|
||||
const adminPassword = 'admin123!';
|
||||
|
||||
console.log('🌱 Starting admin user seeding...');
|
||||
console.log('📧 Admin email:', adminEmail);
|
||||
console.warn('🌱 Starting admin user seeding...');
|
||||
console.warn('📧 Admin email:', adminEmail);
|
||||
|
||||
try {
|
||||
// Check if admin already exists
|
||||
const existingAdmin = await dbService.findUserByEmail(adminEmail);
|
||||
|
||||
if (existingAdmin) {
|
||||
console.log('✅ Default admin user already exists');
|
||||
console.log('👤 Existing admin:', existingAdmin);
|
||||
console.warn('✅ Default admin user already exists');
|
||||
console.warn('👤 Existing admin:', existingAdmin);
|
||||
|
||||
// Check if admin needs to be updated to correct role/status
|
||||
if (
|
||||
existingAdmin.role !== UserRole.ADMIN ||
|
||||
existingAdmin.status !== AccountStatus.ACTIVE
|
||||
) {
|
||||
console.log('🔧 Updating admin user role and status...');
|
||||
console.warn('🔧 Updating admin user role and status...');
|
||||
const updatedAdmin = {
|
||||
...existingAdmin,
|
||||
role: UserRole.ADMIN,
|
||||
@@ -34,13 +34,13 @@ export class DatabaseSeeder {
|
||||
emailVerified: true,
|
||||
};
|
||||
await dbService.updateUser(updatedAdmin);
|
||||
console.log('✅ Admin user updated successfully');
|
||||
console.log('👤 Updated admin:', updatedAdmin);
|
||||
console.warn('✅ Admin user updated successfully');
|
||||
console.warn('👤 Updated admin:', updatedAdmin);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('🔨 Creating new admin user...');
|
||||
console.warn('🚀 Creating new admin user...');
|
||||
// Create default admin user
|
||||
const adminUser = await dbService.createUserWithPassword(
|
||||
adminEmail,
|
||||
@@ -48,7 +48,7 @@ export class DatabaseSeeder {
|
||||
'admin'
|
||||
);
|
||||
|
||||
console.log('👤 Admin user created:', adminUser);
|
||||
console.warn('👤 Admin user created:', adminUser);
|
||||
|
||||
// Update user to admin role and active status
|
||||
const updatedAdmin = {
|
||||
@@ -62,11 +62,11 @@ export class DatabaseSeeder {
|
||||
|
||||
await dbService.updateUser(updatedAdmin);
|
||||
|
||||
console.log('✅ Default admin user created successfully');
|
||||
console.log('👤 Final admin user:', updatedAdmin);
|
||||
console.log('📧 Email:', adminEmail);
|
||||
console.log('🔑 Password:', adminPassword);
|
||||
console.log('⚠️ Please change the default password after first login!');
|
||||
console.warn('✅ Admin user created successfully');
|
||||
console.warn('👤 Final admin user:', updatedAdmin);
|
||||
console.warn('📧 Email:', adminEmail);
|
||||
console.warn('🔑 Password:', adminPassword);
|
||||
console.warn('⚠️ Please change the default password after first login!');
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to create default admin user:', error);
|
||||
throw error;
|
||||
@@ -76,17 +76,17 @@ export class DatabaseSeeder {
|
||||
async seedDatabase(): Promise<void> {
|
||||
// Prevent multiple seeding attempts
|
||||
if (DatabaseSeeder.seedingInProgress || DatabaseSeeder.seedingCompleted) {
|
||||
console.log('🔄 Seeding already in progress or completed, skipping...');
|
||||
console.warn('🔄 Seeding already in progress or completed, skipping...');
|
||||
return;
|
||||
}
|
||||
|
||||
DatabaseSeeder.seedingInProgress = true;
|
||||
console.log('🌱 Starting database seeding...');
|
||||
console.warn('🌱 Starting database seeding...');
|
||||
|
||||
try {
|
||||
await this.seedDefaultAdmin();
|
||||
DatabaseSeeder.seedingCompleted = true;
|
||||
console.log('🎉 Database seeding completed successfully!');
|
||||
console.warn('🎯 Admin seeding completed successfully');
|
||||
} catch (error) {
|
||||
console.error('💥 Database seeding failed:', error);
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user