refactor to adapters
This commit is contained in:
34
adapters/bootstrap/EnsureInitialData.ts
Normal file
34
adapters/bootstrap/EnsureInitialData.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { SignupWithEmailUseCase } from '../../core/identity/application/use-cases/SignupWithEmailUseCase';
|
||||
|
||||
/**
|
||||
* EnsureInitialData - Bootstrap script to ensure initial data exists.
|
||||
* Idempotent: Can be run multiple times without issues.
|
||||
* Calls core use cases to create initial admin user if not exists.
|
||||
*/
|
||||
export class EnsureInitialData {
|
||||
constructor(
|
||||
private readonly signupUseCase: SignupWithEmailUseCase,
|
||||
) {}
|
||||
|
||||
async execute(): Promise<void> {
|
||||
// Ensure initial admin user exists
|
||||
try {
|
||||
await this.signupUseCase.execute({
|
||||
email: 'admin@gridpilot.local',
|
||||
password: 'admin123',
|
||||
displayName: 'Admin',
|
||||
});
|
||||
// User created successfully
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message === 'An account with this email already exists') {
|
||||
// User already exists, nothing to do
|
||||
return;
|
||||
}
|
||||
// Re-throw other errors
|
||||
throw error;
|
||||
}
|
||||
|
||||
// Future: Add more initial data creation here
|
||||
// e.g., create default league, config, etc.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user