2020-04-21 01:07:00 +02:00
|
|
|
import { Column, Entity, JoinTable, ManyToMany, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
2020-04-10 04:04:13 +02:00
|
|
|
import { CharacterTag } from './character-tag';
|
|
|
|
import { InteractionTag } from './interaction-tag';
|
|
|
|
import { TagName } from './tag-name';
|
|
|
|
import { WorkTag } from './work-tag';
|
2019-06-23 02:30:24 +02:00
|
|
|
|
2020-04-10 04:04:13 +02:00
|
|
|
/**
|
|
|
|
* This entity is the main tag entity.
|
|
|
|
* Tags have a name and a description.
|
|
|
|
* They can tag a work, a character, or a character interaction.
|
|
|
|
* They can also be in a hierarchy
|
|
|
|
*/
|
2019-06-23 02:30:24 +02:00
|
|
|
@Entity()
|
2020-04-10 04:04:13 +02:00
|
|
|
export class Tag implements IIdentifiableEntity, IMultiNamedEntity, IDescribableEntity, IHierachicalEntity<Tag> {
|
|
|
|
@PrimaryGeneratedColumn()
|
2020-07-25 02:02:37 +02:00
|
|
|
public id!: number;
|
2020-04-10 04:04:13 +02:00
|
|
|
|
|
|
|
@Column({
|
2019-06-23 02:30:24 +02:00
|
|
|
nullable: false,
|
|
|
|
})
|
2020-07-25 02:02:37 +02:00
|
|
|
public nameCanonical!: string;
|
2019-11-24 16:35:01 +01:00
|
|
|
|
2020-04-10 05:12:14 +02:00
|
|
|
@OneToMany(() => TagName, (tagName: TagName) => tagName.entity)
|
2020-07-25 02:02:37 +02:00
|
|
|
public names!: Promise<TagName[]>;
|
2020-04-10 04:04:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* this tag tagging a work
|
|
|
|
*/
|
2020-04-10 05:12:14 +02:00
|
|
|
@OneToMany(() => WorkTag, (workTag: WorkTag) => workTag.tag)
|
2020-07-25 02:02:37 +02:00
|
|
|
public workTags!: Promise<WorkTag[]>;
|
2020-04-10 04:04:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* this tag tagging characters
|
|
|
|
*/
|
2020-04-10 05:12:14 +02:00
|
|
|
@OneToMany(() => CharacterTag, (characterTag: CharacterTag) => characterTag.tag)
|
2020-07-25 02:02:37 +02:00
|
|
|
public characterTags!: Promise<CharacterTag[]>;
|
2020-04-10 04:04:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* this tag tagging a character interaction
|
|
|
|
*/
|
2020-04-10 05:12:14 +02:00
|
|
|
@OneToMany(() => InteractionTag, (interactionTag: InteractionTag) => interactionTag.tag)
|
2020-07-25 02:02:37 +02:00
|
|
|
public interactionTags!: Promise<InteractionTag[]>;
|
2020-04-10 04:04:13 +02:00
|
|
|
|
2020-04-10 05:12:14 +02:00
|
|
|
@ManyToMany(() => Tag, (tag: Tag) => tag.children)
|
2020-04-21 01:07:00 +02:00
|
|
|
@JoinTable()
|
2020-07-25 02:02:37 +02:00
|
|
|
public parents!: Promise<Tag[]>;
|
2020-04-10 04:04:13 +02:00
|
|
|
|
2020-04-10 05:12:14 +02:00
|
|
|
@ManyToMany(() => Tag, (tag: Tag) => tag.parents)
|
2020-07-25 02:02:37 +02:00
|
|
|
public children!: Promise<Tag[]>;
|
2020-04-10 04:04:13 +02:00
|
|
|
|
|
|
|
@Column({
|
|
|
|
nullable: true,
|
|
|
|
})
|
2020-07-25 02:02:37 +02:00
|
|
|
public description!: string;
|
2020-04-10 04:04:13 +02:00
|
|
|
}
|