30 lines
877 B
TypeScript
30 lines
877 B
TypeScript
import { IsInt } from 'class-validator';
|
|
import { Entity, OneToMany, PrimaryGeneratedColumn, TableInheritance } from 'typeorm';
|
|
import { ResponsePrincipal } from '../responses/ResponsePrincipal';
|
|
import { Permission } from './Permission';
|
|
|
|
/**
|
|
* Defines the principal entity.
|
|
* A principal basicly is any entity that can receive permissions for the api (users and their groups).
|
|
*/
|
|
@Entity()
|
|
@TableInheritance({ column: { name: "type", type: "varchar" } })
|
|
export abstract class Principal {
|
|
/**
|
|
* Autogenerated unique id (primary key).
|
|
*/
|
|
@PrimaryGeneratedColumn()
|
|
@IsInt()
|
|
id: number;
|
|
|
|
/**
|
|
* The participant's permissions.
|
|
*/
|
|
@OneToMany(() => Permission, permission => permission.principal, { nullable: true })
|
|
permissions: Permission[];
|
|
|
|
/**
|
|
* Turns this entity into it's response class.
|
|
*/
|
|
public abstract toResponse(): ResponsePrincipal;
|
|
} |