refactor: implement database service with strategy pattern
- Add DatabaseService with MockDatabaseStrategy and ProductionDatabaseStrategy - Use strategy pattern to switch between test and production database implementations - Improve type safety and testability of database operations - Update database seeder to use new database service architecture This is the foundation for modernizing the database layer.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { dbService } from './couchdb.factory';
|
||||
import { databaseService } from './database';
|
||||
import { AccountStatus } from './auth/auth.constants';
|
||||
import { UserRole } from '../types';
|
||||
|
||||
@@ -15,7 +15,7 @@ export class DatabaseSeeder {
|
||||
|
||||
try {
|
||||
// Check if admin already exists
|
||||
const existingAdmin = await dbService.findUserByEmail(adminEmail);
|
||||
const existingAdmin = await databaseService.findUserByEmail(adminEmail);
|
||||
|
||||
if (existingAdmin) {
|
||||
console.warn('✅ Default admin user already exists');
|
||||
@@ -33,7 +33,7 @@ export class DatabaseSeeder {
|
||||
status: AccountStatus.ACTIVE,
|
||||
emailVerified: true,
|
||||
};
|
||||
await dbService.updateUser(updatedAdmin);
|
||||
await databaseService.updateUser(updatedAdmin);
|
||||
console.warn('✅ Admin user updated successfully');
|
||||
console.warn('👤 Updated admin:', updatedAdmin);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ export class DatabaseSeeder {
|
||||
|
||||
console.warn('🚀 Creating new admin user...');
|
||||
// Create default admin user
|
||||
const adminUser = await dbService.createUserWithPassword(
|
||||
const adminUser = await databaseService.createUserWithPassword(
|
||||
adminEmail,
|
||||
adminPassword,
|
||||
'admin'
|
||||
@@ -60,7 +60,7 @@ export class DatabaseSeeder {
|
||||
lastLoginAt: new Date(),
|
||||
};
|
||||
|
||||
await dbService.updateUser(updatedAdmin);
|
||||
await databaseService.updateUser(updatedAdmin);
|
||||
|
||||
console.warn('✅ Admin user created successfully');
|
||||
console.warn('👤 Final admin user:', updatedAdmin);
|
||||
|
||||
Reference in New Issue
Block a user