@wearesage/schema
Version:
A flexible schema definition and validation system for TypeScript with multi-database support
46 lines (39 loc) • 985 B
text/typescript
import "reflect-metadata";
import { Entity, Id, Property, ManyToMany } from "../..";
import { User } from "./User";
import { Permission } from "./Permission";
/**
* A Role can be assigned to many Users (Many-to-Many).
* A Role can have many Permissions (Many-to-Many).
*/
()
export class Role {
()
id: string;
({ required: true, unique: true })
name: string; // e.g. "ADMIN", "EDITOR", etc.
()
description: string;
({ default: () => new Date() })
createdAt: Date;
/**
* Many-to-many relationship with Users.
*/
({
target: () => User,
inverse: "roles",
name: "ASSIGNED_TO_USER",
})
users: User[] = [];
/**
* Many-to-many relationship with Permissions.
* A role can have many permissions,
* and a permission can belong to many roles.
*/
({
target: () => Permission,
inverse: "roles",
name: "HAS_PERMISSION",
})
permissions: Permission[] = [];
}