feat(auth): implement role seeding on application bootstrap

- Added `onApplicationBootstrap` to seed default roles if none exist.
- Introduced `seedRoles` method to handle role creation with logging.
- Updated `RbacRepository` with `countRoles` and `createRole` methods.
- Added unit tests to ensure role seeding logic functions correctly.
This commit is contained in:
Mathis HERRIOT
2026-01-21 10:45:25 +01:00
parent dd0a9e620b
commit 0548c418c7
3 changed files with 92 additions and 2 deletions

View File

@@ -39,4 +39,22 @@ export class RbacRepository {
return Array.from(new Set(result.map((p) => p.slug)));
}
async countRoles(): Promise<number> {
const result = await this.databaseService.db
.select({ count: roles.id })
.from(roles);
return result.length;
}
async createRole(name: string, slug: string, description?: string) {
return this.databaseService.db
.insert(roles)
.values({
name,
slug,
description,
})
.returning();
}
}