UNPKG

@wearesage/schema

Version:

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

33 lines (28 loc) 755 B
import "reflect-metadata"; import { Entity, Id, Property, ManyToMany } from "../.."; import { Role } from "./Role"; /** * A Permission might be something like "READ", "WRITE", "DELETE". * You can also define "scope" or "resource-level" restrictions here, * or handle them in a linking entity. * For simplicity, we keep it straightforward: */ @Entity() export class Permission { @Id() id: string; @Property({ required: true, unique: true }) name: string; // e.g. "READ", "WRITE", "DELETE" @Property() description: string; /** * Many-to-many with Roles: * A permission can belong to many roles. */ @ManyToMany({ target: () => Role, inverse: "permissions", name: "ASSIGNED_TO_ROLE", }) roles: Role[] = []; }