UNPKG

@wearesage/schema

Version:

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

53 lines (44 loc) 940 B
import "reflect-metadata"; import { Entity, Id, Property, OneToMany, ManyToOne } from "../.."; import { User } from "./User"; import { Post } from "./Post"; import { Reaction } from "./Reaction"; @Entity() export class Comment { @Id() id: string; @Property({ required: true }) content: string; @Property() createdAt: Date; @ManyToOne({ target: () => User, inverse: "comments", name: "AUTHORED_BY", }) author: User; @ManyToOne({ target: () => Post, inverse: "comments", name: "BELONGS_TO_POST", }) post: Post; @OneToMany({ target: () => Comment, inverse: "parentComment", name: "REPLY_TO", }) replies: Comment[] = []; @ManyToOne({ target: () => Comment, inverse: "replies", name: "REPLY_TO", }) parentComment: Comment; @OneToMany({ target: () => Reaction, inverse: "comment", name: "HAS_REACTION", }) reactions: Reaction[] = []; }