UNPKG

@wearesage/schema

Version:

A flexible schema definition and validation system for TypeScript with multi-database support

46 lines (39 loc) 985 B
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). */ @Entity() export class Role { @Id() id: string; @Property({ required: true, unique: true }) name: string; // e.g. "ADMIN", "EDITOR", etc. @Property() description: string; @Property({ default: () => new Date() }) createdAt: Date; /** * Many-to-many relationship with Users. */ @ManyToMany({ 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. */ @ManyToMany({ target: () => Permission, inverse: "roles", name: "HAS_PERMISSION", }) permissions: Permission[] = []; }