src/services/role-store/role-store.service.ts
Methods |
constructor()
|
clearStore |
clearStore()
|
Returns :
void
|
defineManyRoles |
defineManyRoles(roles: [])
|
Returns :
void
|
defineRole |
defineRole(role: Role)
|
Returns :
void
|
getRoleDefinition |
getRoleDefinition(roleName: string)
|
Returns :
Role
|
getStore |
getStore()
|
Returns :
literal type
|
hasRoleDefinition |
hasRoleDefinition(roleName: string)
|
Returns :
boolean
|
removeRoleDefinition |
removeRoleDefinition(roleName: string)
|
Returns :
void
|
import { Injectable } from '@angular/core';
import { Role } from '../../types/role.type';
@Injectable()
export class RoleStoreService {
private roleStore: { [name: string]: Role } = {};
constructor() {}
defineRole(role: Role): void {
if (this.roleStore[role.name]) {
// todo add error list
throw new Error('Role already defined');
}
this.roleStore[role.name] = role;
}
defineManyRoles(roles: Role[]): void {
roles.forEach(role => this.defineRole(role));
}
removeRoleDefinition(roleName: string): void {
delete this.roleStore[roleName];
}
hasRoleDefinition(roleName: string): boolean {
return !!this.roleStore[roleName];
}
getRoleDefinition(roleName: string): Role {
return this.roleStore[roleName];
}
getStore(): { [name: string]: Role } {
return this.roleStore;
}
clearStore(): void {
this.roleStore = {};
}
}