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()
|
@Entity()
|
||||||
export class Ingredient {
|
export class Ingredient {
|
||||||
@@ -13,6 +15,16 @@ export class Ingredient {
|
|||||||
@Column()
|
@Column()
|
||||||
public published: boolean
|
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()
|
@Column()
|
||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
public createdAt?: Date
|
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()
|
@Entity()
|
||||||
export class MetaSchool {
|
export class MetaSchool {
|
||||||
@@ -13,6 +15,13 @@ export class MetaSchool {
|
|||||||
@Column()
|
@Column()
|
||||||
public published: boolean
|
public published: boolean
|
||||||
|
|
||||||
|
@OneToMany(() => School, school => school.metaSchool)
|
||||||
|
public schools?: School[]
|
||||||
|
|
||||||
|
@ManyToOne(() => User, user => user.metaSchools)
|
||||||
|
public creator: User
|
||||||
|
|
||||||
|
// TIMESTAMPS
|
||||||
@Column()
|
@Column()
|
||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
public createdAt?: Date
|
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()
|
@Entity()
|
||||||
export class School {
|
export class School {
|
||||||
@@ -13,6 +16,19 @@ export class School {
|
|||||||
@Column()
|
@Column()
|
||||||
public published: boolean
|
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()
|
@Column()
|
||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
public createdAt?: Date
|
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()
|
@Entity()
|
||||||
export class Spell {
|
export class Spell {
|
||||||
@@ -25,6 +29,20 @@ export class Spell {
|
|||||||
@Column()
|
@Column()
|
||||||
public public?: boolean
|
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()
|
@Column()
|
||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
public createdAt?: Date
|
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()
|
@Entity()
|
||||||
export class Variable {
|
export class Variable {
|
||||||
@@ -11,6 +13,16 @@ export class Variable {
|
|||||||
@Column()
|
@Column()
|
||||||
public published: boolean
|
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()
|
@Column()
|
||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
public createdAt?: Date
|
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()
|
@Entity()
|
||||||
export class Permission {
|
export class Permission {
|
||||||
@@ -8,6 +9,10 @@ export class Permission {
|
|||||||
@Column()
|
@Column()
|
||||||
public slug!: string
|
public slug!: string
|
||||||
|
|
||||||
|
@ManyToOne(() => Role, role => role.permissions)
|
||||||
|
public roles: Role[]
|
||||||
|
|
||||||
|
// TIMESTAMPS
|
||||||
@Column()
|
@Column()
|
||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
public createdAt?: Date
|
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()
|
@Entity()
|
||||||
export class Role {
|
export class Role {
|
||||||
@@ -10,6 +12,13 @@ export class Role {
|
|||||||
@Column()
|
@Column()
|
||||||
public description!: string
|
public description!: string
|
||||||
|
|
||||||
|
@OneToMany(() => Permission, permission => permission.roles)
|
||||||
|
public permissions: Permission[]
|
||||||
|
|
||||||
|
@OneToMany(() => User, user => user.role)
|
||||||
|
public users: User[]
|
||||||
|
|
||||||
|
// TIMESTAMPS
|
||||||
@Column()
|
@Column()
|
||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
public createdAt?: Date
|
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()
|
@Entity()
|
||||||
export class User {
|
export class User {
|
||||||
@@ -20,6 +26,27 @@ export class User {
|
|||||||
@Column()
|
@Column()
|
||||||
public verified: boolean
|
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()
|
@Column()
|
||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
public createdAt?: Date
|
public createdAt?: Date
|
||||||
|
|||||||
Reference in New Issue
Block a user