2020-04-21 01:07:00 +02:00
|
|
|
import { Column, Entity, JoinTable, ManyToMany, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
2020-04-10 04:04:13 +02:00
|
|
|
import { Author } from './author';
|
|
|
|
import { AuthorRole } from './author-role';
|
|
|
|
import { Work } from './work';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This entity connects authors with their work and their role therein.
|
|
|
|
*/
|
|
|
|
@Entity()
|
|
|
|
export class WorkAuthor implements IIdentifiableEntity, IOrderableEntity {
|
|
|
|
@PrimaryGeneratedColumn()
|
|
|
|
public id: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the work
|
|
|
|
*/
|
2020-04-10 05:12:14 +02:00
|
|
|
@ManyToOne(() => Work, (work: Work) => work.workAuthors, {
|
|
|
|
nullable: false,
|
|
|
|
onDelete: 'CASCADE',
|
|
|
|
onUpdate: 'CASCADE',
|
|
|
|
})
|
2020-04-10 04:04:13 +02:00
|
|
|
public work: Promise<Work>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the roles of the author in the work
|
|
|
|
*/
|
2020-04-10 05:12:14 +02:00
|
|
|
@ManyToMany(() => AuthorRole, (authorRole: AuthorRole) => authorRole.workAuthors)
|
2020-04-21 01:07:00 +02:00
|
|
|
@JoinTable()
|
2020-04-10 04:04:13 +02:00
|
|
|
public authorRoles: Promise<AuthorRole[]>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the author
|
|
|
|
*/
|
2020-04-10 05:12:14 +02:00
|
|
|
@ManyToOne(() => Author, (author: Author) => author.workAuthors, {
|
|
|
|
nullable: false,
|
|
|
|
onDelete: 'RESTRICT',
|
|
|
|
onUpdate: 'CASCADE',
|
|
|
|
})
|
2020-04-10 04:04:13 +02:00
|
|
|
public author: Promise<Author>;
|
|
|
|
|
|
|
|
@Column({
|
|
|
|
nullable: false,
|
|
|
|
default: 0,
|
|
|
|
})
|
|
|
|
public order: number;
|
|
|
|
}
|