38 lines
877 B
TypeScript
38 lines
877 B
TypeScript
import { Column, Entity, JoinTable, ManyToMany, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
|
import { Source } from './source';
|
|
import { Work } from './work';
|
|
|
|
@Entity()
|
|
export class Copy implements CopyEntityInterface {
|
|
@PrimaryGeneratedColumn()
|
|
public readonly id!: number;
|
|
|
|
@ManyToOne(() => Work, (work: WorkEntityInterface) => work.copies, {
|
|
nullable: false,
|
|
onDelete: 'CASCADE',
|
|
onUpdate: 'CASCADE',
|
|
})
|
|
public original!: Promise<WorkEntityInterface>;
|
|
|
|
@ManyToMany(() => Source, (source: SourceEntityInterface) => source.copies)
|
|
@JoinTable()
|
|
public sources!: Promise<SourceEntityInterface[]>;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
default: '',
|
|
})
|
|
public hash!: string;
|
|
|
|
@Column('text', {
|
|
nullable: true,
|
|
})
|
|
public location!: string | null;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
default: 0,
|
|
})
|
|
public ranking!: number;
|
|
}
|