RenaiApp/src/main/entities/library/work.ts

77 lines
2.6 KiB
TypeScript
Raw Normal View History

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<WorkNameEntityInterface[]>;
@OneToMany(() => Copy, (copy: CopyEntityInterface) => copy.original, {})
public copies!: Promise<CopyEntityInterface[]>;
@OneToMany(() => Transformation, (transformation: TransformationEntityInterface) => transformation.byWork)
public transformationOf!: Promise<TransformationEntityInterface[]>;
@OneToMany(() => Transformation, (transformation: TransformationEntityInterface) => transformation.ofWork)
public transformedBy!: Promise<TransformationEntityInterface[]>;
@OneToMany(() => WorkAuthor, (workAuthor: WorkAuthorEntityInterface) => workAuthor.work)
public workAuthors!: Promise<WorkAuthorEntityInterface[]>;
@OneToMany(() => WorkTag, (workTag: WorkTagEntityInterface) => workTag.work)
public workTags!: Promise<WorkTagEntityInterface[]>;
@ManyToMany(() => WorkCharacter, (workCharacter: WorkCharacterEntityInterface) => workCharacter.works)
@JoinTable()
public workCharacters!: Promise<WorkCharacterEntityInterface[]>;
@ManyToMany(() => World, (world: WorldEntityInterface) => world.works)
@JoinTable()
public worlds!: Promise<WorldEntityInterface[]>;
@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<LanguageEntityInterface[]>;
/**
* the collections this work is a part of
*/
@OneToMany(() => CollectionPart, (collectionPart: CollectionPartEntityInterface) => collectionPart.work)
public collectionParts!: Promise<CollectionPartEntityInterface[]>;
}