40 lines
964 B
TypeScript
40 lines
964 B
TypeScript
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
|
import { Collection } from './collection';
|
|
import { Work } from './work';
|
|
|
|
/**
|
|
* This entity orders works in a collection.
|
|
* The main use case is chronological ordering.
|
|
*/
|
|
@Entity()
|
|
export class CollectionPart implements IdentifiableEntityInterface, OrderableEntityInterface {
|
|
@PrimaryGeneratedColumn()
|
|
public id!: number;
|
|
|
|
/**
|
|
* the collection thw work is a part of
|
|
*/
|
|
@ManyToOne(() => Collection, (collection: Collection) => collection.parts, {
|
|
nullable: false,
|
|
onDelete: 'CASCADE',
|
|
onUpdate: 'CASCADE',
|
|
})
|
|
public collection!: Promise<Collection>;
|
|
|
|
/**
|
|
* the work inside the collection
|
|
*/
|
|
@ManyToOne(() => Work, (work: Work) => work.collectionParts, {
|
|
nullable: false,
|
|
onDelete: 'CASCADE',
|
|
onUpdate: 'CASCADE',
|
|
})
|
|
public work!: Promise<Work>;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
default: 0,
|
|
})
|
|
public order!: number;
|
|
}
|