Passed
Push — master ( 24a438...ac8bb2 )
by Sergey
04:17
created

src/services/rbac.service.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 31
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 24
mnd 1
bc 1
fnc 1
dl 0
loc 31
bpm 1
cpm 2
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A RbacService.getRole 0 12 2
1
import { Injectable } from '@nestjs/common';
2
import { IRbac } from './interfaces/rbac.interface';
3
import { StorageRbacService } from './storage.rbac.service';
4
import { RoleRbac } from '../role/role.rbac';
5
import { IRoleRbac } from '../role/interfaces/role.rbac.interface';
6
import { RbacExceptions } from '../exceptions/rbac.exceptions';
7
import { IParamsFilter } from '../params-filter/interfaces/params.filter.interface';
8
9
@Injectable()
10
export class RbacService implements IRbac {
11
12
  constructor(
13
    private readonly  storageRbacService: StorageRbacService,
14
  ) {
15
  }
16
17
  async getRole(role: string, paramsFilter?: IParamsFilter): Promise<IRoleRbac> {
18
    const storage = await this.storageRbacService.getStorage();
19
    if (!storage.roles || !storage.roles.includes(role)) {
20
      throw new RbacExceptions('There is no exist a role.');
21
    }
22
23
    return new RoleRbac(
24
      role,
25
      await this.storageRbacService.getGrant(role),
26
      await this.storageRbacService.getFilters(),
27
      paramsFilter,
28
    );
29
  }
30
}
31