-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(model): add models methods impl
- Loading branch information
1 parent
6c4099b
commit b68d960
Showing
3 changed files
with
33 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Principal } from '../entities/principal.entity'; | ||
import { Role } from '../entities/role.entity'; | ||
|
||
@Injectable() | ||
export class PrincipalModel { | ||
principalsDb: Record<string, Principal>; | ||
constructor() {} | ||
|
||
create(roles: Role[]) {} | ||
findById(id: string) {} | ||
assignRoles(id: string, roles: Role[]) {} | ||
create(roles: string[]) { | ||
const newPrincipal = new Principal(roles); | ||
this.principalsDb[newPrincipal.id] = newPrincipal; | ||
return newPrincipal; | ||
} | ||
findById(id: string) { | ||
return this.principalsDb[id]; | ||
} | ||
assignRoles(id: string, roles: string[]) { | ||
this.principalsDb[id].roles = roles; | ||
return this.principalsDb[id]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Role } from '../entities/role.entity'; | ||
import { Scope } from '../entities/scope.entity'; | ||
import { ScopeModel } from './scope.model'; | ||
|
||
@Injectable() | ||
export class RoleModel { | ||
rolesDb: Record<string, Role>; | ||
constructor() {} | ||
constructor(private readonly scopeModel: ScopeModel) {} | ||
|
||
create(scopes: Scope[]) {} | ||
findById(id: string) {} | ||
update(id: string, roles: Role[]) {} | ||
create(name: string, scopes: string[]) { | ||
const newRole = new Role(name, scopes); | ||
this.rolesDb[newRole.id] = newRole; | ||
return newRole; | ||
} | ||
findById(ids: string[]) { | ||
return ids.map((id) => this.rolesDb[id]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters