UNPKG

@wearesage/schema

Version:

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

38 lines (31 loc) 690 B
import "reflect-metadata"; import { Entity, Id, Property, ManyToOne } from "../.."; import { User } from "./User"; import { Product } from "./Product"; /** * A Review belongs to exactly one User (the author), * and exactly one Product. */ @Entity() export class Review { @Id() id: string; @Property({ required: true }) content: string; @Property() rating: number; // e.g. 1-5 @Property({ default: () => new Date() }) createdAt: Date; @ManyToOne({ target: () => User, inverse: "reviews", name: "AUTHORED_BY", }) author: User; @ManyToOne({ target: () => Product, inverse: "reviews", name: "REVIEWS_PRODUCT", }) product: Product; }