import { Column, Entity, JoinTable, ManyToMany, OneToMany, PrimaryGeneratedColumn } from 'typeorm'; import { PercentCheck } from '../decorators/percent-check'; import { CollectionPart } from './collection-part'; import { Copy } from './copy'; import { Language } from './language'; import { Transformation } from './transformation'; import { WorkAuthor } from './work-author'; import { WorkCharacter } from './work-character'; import { WorkName } from './work-name'; import { WorkTag } from './work-tag'; import { World } from './world'; @Entity() @PercentCheck('rating') export class Work implements WorkEntityInterface { @PrimaryGeneratedColumn() public readonly id!: number; @Column({ nullable: false, default: '', }) public nameCanonical!: string; @OneToMany(() => WorkName, (workName: WorkNameEntityInterface) => workName.entity) public names!: Promise; @OneToMany(() => Copy, (copy: CopyEntityInterface) => copy.original, {}) public copies!: Promise; @OneToMany(() => Transformation, (transformation: TransformationEntityInterface) => transformation.byWork) public transformationOf!: Promise; @OneToMany(() => Transformation, (transformation: TransformationEntityInterface) => transformation.ofWork) public transformedBy!: Promise; @OneToMany(() => WorkAuthor, (workAuthor: WorkAuthorEntityInterface) => workAuthor.work) public workAuthors!: Promise; @OneToMany(() => WorkTag, (workTag: WorkTagEntityInterface) => workTag.work) public workTags!: Promise; @ManyToMany(() => WorkCharacter, (workCharacter: WorkCharacterEntityInterface) => workCharacter.works) @JoinTable() public workCharacters!: Promise; @ManyToMany(() => World, (world: WorldEntityInterface) => world.works) @JoinTable() public worlds!: Promise; @Column({ nullable: false, default: false, }) public isCanonical!: boolean; @Column('int', { nullable: true, }) public rating!: number | null; @Column('date', { nullable: true, }) public releaseDate!: string | null; @ManyToMany(() => Language, (language: LanguageEntityInterface) => language.works) @JoinTable() public languages!: Promise; /** * the collections this work is a part of */ @OneToMany(() => CollectionPart, (collectionPart: CollectionPartEntityInterface) => collectionPart.work) public collectionParts!: Promise; }