1.0.2 • Published 4 years ago

@reactive-underground/permissions v1.0.2

Weekly downloads
42
License
MIT
Repository
github
Last release
4 years ago

Installation

npm install -S @reactive-underground/permissions

Use as nestjs module

imports: [
    PermissionModule.forRoot({
        repository: {
            role: SqlRoleRepository,
            permission: SqlPermissionRepository
        },
        controller: {
            prefix: "api/v1"
        },
        root: {
            name: 'root'
        }
    })
]

Permission Decorator

@Controller("app")
export class AppController {

  @Permissions("app.test")
  @Get("test")  
  public test(): string {
    return "test";
  }
}

Create roles

export class AppModule implements OnModuleInit {
    constructor(
        private readonly roleService: RoleService
    ) {}

    public async onInit() {
        try {
            await this.roleService.create({
                name: 'root',
                persistence: true,
                title: 'Root'
            })
        } catch (e) {
            // role already exists
        }    

    }
}