parent
dc485c02ea
commit
145a08b1b4
|
@ -1,5 +1,6 @@
|
|||
import { IsInt, IsOptional } from 'class-validator';
|
||||
import { Entity, OneToMany, PrimaryGeneratedColumn, TableInheritance } from 'typeorm';
|
||||
import { ResponsePrincipal } from '../responses/ResponsePrincipal';
|
||||
import { Permission } from './Permission';
|
||||
|
||||
/**
|
||||
|
@ -21,4 +22,6 @@ export abstract class Principal {
|
|||
@IsOptional()
|
||||
@OneToMany(() => Permission, permission => permission.principal, { nullable: true })
|
||||
permissions?: Permission[];
|
||||
|
||||
public abstract toResponse(): ResponsePrincipal;
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString, IsUUID } from "class-validator";
|
||||
import { ChildEntity, Column, JoinTable, ManyToMany, OneToMany } from "typeorm";
|
||||
import { config } from '../../config';
|
||||
import { ResponsePrincipal } from '../responses/ResponsePrincipal';
|
||||
import { ResponseUser } from '../responses/ResponseUser';
|
||||
import { Permission } from './Permission';
|
||||
import { Principal } from './Principal';
|
||||
import { UserAction } from './UserAction';
|
||||
|
@ -126,4 +128,8 @@ export class User extends Principal {
|
|||
})
|
||||
return final_permissions
|
||||
}
|
||||
|
||||
public toResponse(): ResponsePrincipal {
|
||||
return new ResponseUser(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import {
|
|||
IsString
|
||||
} from "class-validator";
|
||||
import { ChildEntity, Column } from "typeorm";
|
||||
import { ResponsePrincipal } from '../responses/ResponsePrincipal';
|
||||
import { ResponseUserGroup } from '../responses/ResponseUserGroup';
|
||||
import { Principal } from './Principal';
|
||||
|
||||
/**
|
||||
|
@ -27,4 +29,8 @@ export class UserGroup extends Principal {
|
|||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
|
||||
public toResponse(): ResponsePrincipal {
|
||||
return new ResponseUserGroup(this);
|
||||
}
|
||||
}
|
|
@ -4,9 +4,9 @@ import {
|
|||
IsObject
|
||||
} from "class-validator";
|
||||
import { Permission } from '../entities/Permission';
|
||||
import { Principal } from '../entities/Principal';
|
||||
import { PermissionAction } from '../enums/PermissionAction';
|
||||
import { PermissionTarget } from '../enums/PermissionTargets';
|
||||
import { ResponsePrincipal } from './ResponsePrincipal';
|
||||
|
||||
/**
|
||||
* Defines a track of given length.
|
||||
|
@ -23,7 +23,7 @@ export class ResponsePermission {
|
|||
*/
|
||||
@IsObject()
|
||||
@IsNotEmpty()
|
||||
principal: Principal;
|
||||
principal: ResponsePrincipal;
|
||||
|
||||
/**
|
||||
* The permissions's target.
|
||||
|
@ -39,7 +39,7 @@ export class ResponsePermission {
|
|||
|
||||
public constructor(permission: Permission) {
|
||||
this.id = permission.id;
|
||||
this.principal = permission.principal;
|
||||
this.principal = permission.principal.toResponse();
|
||||
this.target = permission.target;
|
||||
this.action = permission.action;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
import {
|
||||
IsArray,
|
||||
|
||||
|
||||
IsNotEmpty,
|
||||
|
||||
IsOptional,
|
||||
IsString
|
||||
} from "class-validator";
|
||||
import { Permission } from '../entities/Permission';
|
||||
import { UserGroup } from '../entities/UserGroup';
|
||||
import { ResponsePrincipal } from './ResponsePrincipal';
|
||||
|
||||
/**
|
||||
* Defines a user response.
|
||||
*/
|
||||
export class ResponseUserGroup extends ResponsePrincipal {
|
||||
/**
|
||||
* The group's name
|
||||
*/
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* The group's description
|
||||
*/
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
|
||||
/**
|
||||
* permissions
|
||||
*/
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
permissions: Permission[];
|
||||
|
||||
public constructor(group: UserGroup) {
|
||||
super(group);
|
||||
this.name = group.name;
|
||||
this.description = group.description;
|
||||
this.permissions = group.permissions;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue