Skip to content

Commit

Permalink
feat(model): add models methods impl
Browse files Browse the repository at this point in the history
  • Loading branch information
notusertelken committed Sep 19, 2022
1 parent 6c4099b commit b68d960
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
16 changes: 12 additions & 4 deletions src/domain/model/principal.model.ts
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];
}
}
15 changes: 10 additions & 5 deletions src/domain/model/role.model.ts
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]);
}
}
15 changes: 11 additions & 4 deletions src/domain/model/scope.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ import { Injectable } from '@nestjs/common';
import { Scope } from '../entities/scope.entity';

@Injectable()
export class RoleModel {
export class ScopeModel {
scopesDb: Record<string, Scope>;
constructor() {}

create(urn: string, context: string) {}
findById(id: string) {}
update(id: string, urn: string, context: string) {}
create(scopes: { urn: string; context: string }[]) {
return scopes.map((scope) => {
const newScope = new Scope(scope.urn, scope.context);
this.scopesDb[newScope.id] = newScope;
return newScope;
});
}
findById(ids: string[]) {
return ids.map((id) => this.scopesDb[id]);
}
}

0 comments on commit b68d960

Please sign in to comment.