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