Added relationships to entities
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
||||
import { Column, CreateDateColumn, Entity, JoinTable, ManyToMany, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
||||
import { User } from "../users/User";
|
||||
import { Spell } from "./Spell";
|
||||
|
||||
@Entity()
|
||||
export class Ingredient {
|
||||
@@ -13,6 +15,16 @@ export class Ingredient {
|
||||
@Column()
|
||||
public published: boolean
|
||||
|
||||
@ManyToMany(() => Spell, spell => spell.ingredients)
|
||||
@JoinTable({
|
||||
name: 'ingredients_spells'
|
||||
})
|
||||
public spells?: Spell[]
|
||||
|
||||
@ManyToOne(() => User, user => user.ingredients)
|
||||
public creator: User
|
||||
|
||||
// TIMESTAMPS
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
public createdAt?: Date
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm"
|
||||
import { Column, CreateDateColumn, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm"
|
||||
import { User } from "../users/User"
|
||||
import { School } from "./School"
|
||||
|
||||
@Entity()
|
||||
export class MetaSchool {
|
||||
@@ -13,6 +15,13 @@ export class MetaSchool {
|
||||
@Column()
|
||||
public published: boolean
|
||||
|
||||
@OneToMany(() => School, school => school.metaSchool)
|
||||
public schools?: School[]
|
||||
|
||||
@ManyToOne(() => User, user => user.metaSchools)
|
||||
public creator: User
|
||||
|
||||
// TIMESTAMPS
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
public createdAt?: Date
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
||||
import { Column, CreateDateColumn, Entity, JoinTable, ManyToMany, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
||||
import { User } from "../users/User";
|
||||
import { MetaSchool } from "./MetaSchool";
|
||||
import { Spell } from "./Spell";
|
||||
|
||||
@Entity()
|
||||
export class School {
|
||||
@@ -13,6 +16,19 @@ export class School {
|
||||
@Column()
|
||||
public published: boolean
|
||||
|
||||
@ManyToMany(() => Spell, spell => spell.schools)
|
||||
@JoinTable({
|
||||
name: 'schools_spells'
|
||||
})
|
||||
public spells?: Spell[]
|
||||
|
||||
@ManyToOne(() => MetaSchool, metaSchool => metaSchool.schools)
|
||||
public metaSchool: MetaSchool
|
||||
|
||||
@ManyToOne(() => User, user => user.schools)
|
||||
public creator: User
|
||||
|
||||
// TIMESTAMPS
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
public createdAt?: Date
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm"
|
||||
import { Column, CreateDateColumn, Entity, JoinTable, ManyToMany, ManyToOne, OneToMany, OneToOne, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm"
|
||||
import { User } from "../users/User"
|
||||
import { Ingredient } from "./Ingredient"
|
||||
import { School } from "./School"
|
||||
import { Variable } from "./Variable"
|
||||
|
||||
@Entity()
|
||||
export class Spell {
|
||||
@@ -25,6 +29,20 @@ export class Spell {
|
||||
@Column()
|
||||
public public?: boolean
|
||||
|
||||
// LINKED ENTITIES
|
||||
@ManyToMany(() => School, school => school.spells)
|
||||
public schools?: School[]
|
||||
|
||||
@ManyToMany(() => Variable, variable => variable.spells)
|
||||
public variables?: Variable[]
|
||||
|
||||
@ManyToMany(() => Ingredient, ingredient => ingredient.spells)
|
||||
public ingredients?: Ingredient[]
|
||||
|
||||
@ManyToOne(() => User, user => user.spells)
|
||||
public creator: User
|
||||
|
||||
// TIMESTAMPS
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
public createdAt?: Date
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
||||
import { Column, CreateDateColumn, Entity, JoinTable, ManyToMany, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
||||
import { User } from "../users/User";
|
||||
import { Spell } from "./Spell";
|
||||
|
||||
@Entity()
|
||||
export class Variable {
|
||||
@@ -11,6 +13,16 @@ export class Variable {
|
||||
@Column()
|
||||
public published: boolean
|
||||
|
||||
@ManyToMany(() => Spell, spell => spell.variables)
|
||||
@JoinTable({
|
||||
name: 'variables_spells'
|
||||
})
|
||||
public spells?: Spell[]
|
||||
|
||||
@ManyToOne(() => User, user => user.variables)
|
||||
public creator: User
|
||||
|
||||
// TIMESTAMPS
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
public createdAt?: Date
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
||||
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
||||
import { Role } from "./Role";
|
||||
|
||||
@Entity()
|
||||
export class Permission {
|
||||
@@ -8,6 +9,10 @@ export class Permission {
|
||||
@Column()
|
||||
public slug!: string
|
||||
|
||||
@ManyToOne(() => Role, role => role.permissions)
|
||||
public roles: Role[]
|
||||
|
||||
// TIMESTAMPS
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
public createdAt?: Date
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
||||
import { Column, CreateDateColumn, Entity, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
||||
import { Permission } from "./Permission";
|
||||
import { User } from "./User";
|
||||
|
||||
@Entity()
|
||||
export class Role {
|
||||
@@ -10,6 +12,13 @@ export class Role {
|
||||
@Column()
|
||||
public description!: string
|
||||
|
||||
@OneToMany(() => Permission, permission => permission.roles)
|
||||
public permissions: Permission[]
|
||||
|
||||
@OneToMany(() => User, user => user.role)
|
||||
public users: User[]
|
||||
|
||||
// TIMESTAMPS
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
public createdAt?: Date
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm"
|
||||
import { Column, CreateDateColumn, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm"
|
||||
import { Ingredient } from "../spells/Ingredient"
|
||||
import { MetaSchool } from "../spells/MetaSchool"
|
||||
import { School } from "../spells/School"
|
||||
import { Spell } from "../spells/Spell"
|
||||
import { Variable } from "../spells/Variable"
|
||||
import { Role } from "./Role"
|
||||
|
||||
@Entity()
|
||||
export class User {
|
||||
@@ -20,6 +26,27 @@ export class User {
|
||||
@Column()
|
||||
public verified: boolean
|
||||
|
||||
// CREATIONS
|
||||
@OneToMany(() => Spell, spell => spell.creator)
|
||||
public spells?: Spell[]
|
||||
|
||||
@OneToMany(() => School, school => school.creator)
|
||||
public schools?: School[]
|
||||
|
||||
@OneToMany(() => Variable, variable => variable.creator)
|
||||
public variables?: Variable[]
|
||||
|
||||
@OneToMany(() => Ingredient, ingredients => ingredients.creator)
|
||||
public ingredients?: Ingredient[]
|
||||
|
||||
@OneToMany(() => MetaSchool, metaSchools => metaSchools.creator)
|
||||
public metaSchools?: Ingredient[]
|
||||
|
||||
// ROLE
|
||||
@ManyToOne(() => Role, role => role.users)
|
||||
public role: Role
|
||||
|
||||
// TIMESTAMPS
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
public createdAt?: Date
|
||||
|
||||
Reference in New Issue
Block a user