import { Column, Entity, ManyToMany, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; import { Source } from './source'; import { Work } from './work'; /** * A copy is the digital counterpart of a work. * It corresponds to a unique file or set of files which represent the work on the users device. * * Multiple works can have multiple copies (think of different scans of a physical work, or lossy compression). */ @Entity() export class Copy implements IIdentifiableEntity { @PrimaryGeneratedColumn() public id: number; /** * the work this entity is a copy of */ @ManyToOne(() => Work, (work: Work) => work.copies, { nullable: false, onDelete: 'CASCADE', onUpdate: 'CASCADE', }) public original: Promise; /** * where to find this specific copy */ @ManyToMany(() => Source, (source: Source) => source.copies) public sources: Promise; /** * identifying hash of the file contents */ @Column({ nullable: false, }) public hash: string; /** * device location of the copy */ @Column({ nullable: true, }) public location: string; /** * the ordering of the copies belonging to the same work, * lower number is higher ranked */ @Column({ nullable: false, default: 0, }) public ranking: number; }