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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user