@wearesage/schema
Version:
A flexible schema definition and validation system for TypeScript with multi-database support
67 lines (57 loc) • 1.37 kB
text/typescript
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).
*/
()
export class Product {
()
id: string;
({ required: true })
name: string;
()
description: string;
()
price: number;
()
createdAt: Date;
({
target: () => Category,
inverse: "products",
name: "BELONGS_TO_CATEGORY",
})
categories: Category[] = [];
/**
* A product can appear in many cart items.
*/
({
target: () => CartItem,
inverse: "product",
name: "INCLUDES_PRODUCT",
})
cartItems: CartItem[] = [];
/**
* A product can appear in many order items.
*/
({
target: () => OrderItem,
inverse: "product",
name: "ORDERED_PRODUCT",
})
orderItems: OrderItem[] = [];
/**
* A product can have many reviews.
*/
({
target: () => Review,
inverse: "product",
name: "HAS_REVIEW",
})
reviews: Review[] = [];
}