UNPKG

@wearesage/schema

Version:

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

67 lines (57 loc) 1.37 kB
import "reflect-metadata"; import { Entity, Id, Property, OneToMany, ManyToMany } from "../.."; import { Category } from "./Category"; import { CartItem } from "./CartItem"; import { OrderItem } from "./OrderItem"; import { Review } from "./Review"; /** * A Product can belong to many Categories (Many-to-Many), * can appear in multiple CartItems (One-to-Many side from CartItem), * and can be part of multiple OrderItems (one product, many order items). */ @Entity() export class Product { @Id() id: string; @Property({ required: true }) name: string; @Property() description: string; @Property() price: number; @Property() createdAt: Date; @ManyToMany({ target: () => Category, inverse: "products", name: "BELONGS_TO_CATEGORY", }) categories: Category[] = []; /** * A product can appear in many cart items. */ @OneToMany({ target: () => CartItem, inverse: "product", name: "INCLUDES_PRODUCT", }) cartItems: CartItem[] = []; /** * A product can appear in many order items. */ @OneToMany({ target: () => OrderItem, inverse: "product", name: "ORDERED_PRODUCT", }) orderItems: OrderItem[] = []; /** * A product can have many reviews. */ @OneToMany({ target: () => Review, inverse: "product", name: "HAS_REVIEW", }) reviews: Review[] = []; }