Generator Module

Generator Module serve as a foundational setup tool for initializing projects. They are specifically designed to define and manage services that generate test data or essential initial data at the beginning of a project.

Role and Permission Generator Service

The Role and Permission Generator Service comes as a default part of the Generator Module. This means that it’s already set up and ready to use when you start a new project.
Primary Role: To automatically create default roles and permissions within your application.

Using createRoleAndPermission Method

In this example, YourCustomPermissionArray, YourPermissionType, and YourRoleAlias are placeholders for your specific permission array, type, and role alias, respectively.
// Example usage within your application
await this.rolePermissionGeneratorService.createRoleAndPermission({
  permission: YourCustomPermissionArray,
  type: YourPermissionType,
  roleAlias: YourRoleAlias,
  title: "Custom Role Title",
});

Implementation in AppModule

In the AppModule, the Role and Permission Generator Service is defined as follows:
// In AppModule
export class AppModule implements OnModuleInit {
  constructor(
    private readonly rolePermissionGeneratorService: RolePermissionGeneratorService
  ) {}
  async onModuleInit() {
    console.log("Initializing Generator Services...");
    await this.rolePermissionGeneratorService.createDefaultRoleAndPermissions();
  }
}

Triggering Generation with a Boolean

The generation process is controlled by a boolean flag. The createDefaultRoleAndPermissions method uses this flag to determine whether to generate roles and permissions. Set generateRolesAndPermission to true to activate the generation each time the application starts.
// In RolePermissionGeneratorService
async createDefaultRoleAndPermissions(): Promise<void> {
  const generateRolesAndPermission = true; // Set to true to generate roles and permissions
  // ... rest of the method
}