34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
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.
|
|
}
|
|
} |