This commit is contained in:
2025-12-16 15:42:38 +01:00
parent 29410708c8
commit 362894d1a5
147 changed files with 780 additions and 375 deletions

View File

@@ -1,13 +1,19 @@
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.
*/
import { SignupWithEmailUseCase } from '@core/identity/application/use-cases/SignupWithEmailUseCase';
import { CreateAchievementUseCase } from '@core/identity/application/use-cases/achievement/CreateAchievementUseCase';
import type { Logger } from '@core/shared/application/Logger';
import {
DRIVER_ACHIEVEMENTS,
STEWARD_ACHIEVEMENTS,
ADMIN_ACHIEVEMENTS,
COMMUNITY_ACHIEVEMENTS,
} from '@core/identity/domain/AchievementConstants';
export class EnsureInitialData {
constructor(
private readonly signupUseCase: SignupWithEmailUseCase,
private readonly createAchievementUseCase: CreateAchievementUseCase,
private readonly logger: Logger,
) {}
async execute(): Promise<void> {
@@ -18,17 +24,38 @@ export class EnsureInitialData {
password: 'admin123',
displayName: 'Admin',
});
// User created successfully
this.logger.info('[Bootstrap] Initial admin user created');
} catch (error) {
if (error instanceof Error && error.message === 'An account with this email already exists') {
// User already exists, nothing to do
return;
this.logger.info('[Bootstrap] Admin user already exists');
} else {
// Re-throw other errors
throw error;
}
// Re-throw other errors
throw error;
}
// Future: Add more initial data creation here
// e.g., create default league, config, etc.
// Ensure initial achievements exist
const allAchievements = [
...DRIVER_ACHIEVEMENTS,
...STEWARD_ACHIEVEMENTS,
...ADMIN_ACHIEVEMENTS,
...COMMUNITY_ACHIEVEMENTS,
];
let createdCount = 0;
let existingCount = 0;
for (const achievementProps of allAchievements) {
try {
await this.createAchievementUseCase.execute(achievementProps);
createdCount++;
} catch {
// If achievement already exists, that's fine
existingCount++;
}
}
this.logger.info(`[Bootstrap] Achievements: ${createdCount} created, ${existingCount} already exist`);
}
}

View File

@@ -0,0 +1,19 @@
import { IAchievementRepository } from "@core/identity/application/use-cases/achievement/CreateAchievementUseCase";
import { Achievement } from "@core/identity/domain/entities/Achievement";
export class InMemoryAchievementRepository implements IAchievementRepository {
private readonly achievements: Map<string, Achievement> = new Map();
async save(achievement: Achievement): Promise<void> {
this.achievements.set(achievement.id, achievement);
}
async findById(id: string): Promise<Achievement | null> {
return this.achievements.get(id) || null;
}
async findAll(): Promise<Achievement[]> {
return Array.from(this.achievements.values());
}
}

View File

@@ -1,21 +1,12 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "dist",
"baseUrl": ".",
"composite": true,
"outDir": "../dist/adapters",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"types": ["vitest/globals"],
"paths": {
"@/*": ["./*"],
"@core/*": ["../core/*"],
"@adapters/*": ["./*"],
"@testing/*": ["../testing/*"]
}
"types": ["vitest/globals"]
},
"include": ["**/*.ts"],
"include": ["**/*.ts", "../core/**/*.ts"],
"exclude": ["node_modules", "dist"]
}