import { Entity, Column, ManyToOne, ManyToMany, JoinTable } from 'typeorm'; import { SpaceEntity } from './space.entity'; import { SpaceModelProductAllocationEntity } from '../../space-model'; import { ProductEntity } from '../../product/entities'; import { NewTagEntity } from '../../tag'; @Entity({ name: 'space_product_allocation' }) export class SpaceProductAllocationEntity { @Column({ type: 'uuid', default: () => 'gen_random_uuid()', nullable: false, }) public uuid: string; @ManyToOne(() => SpaceEntity, (space) => space.productAllocations, { nullable: false, onDelete: 'CASCADE', }) public space: SpaceEntity; @ManyToOne(() => SpaceModelProductAllocationEntity, { nullable: true, onDelete: 'SET NULL', }) public inheritedFromModel?: SpaceModelProductAllocationEntity; @ManyToOne(() => ProductEntity, { nullable: false, onDelete: 'CASCADE' }) public product: ProductEntity; @Column({ type: 'int', default: 1 }) public allowedQuantity: number; @ManyToMany(() => NewTagEntity) @JoinTable({ name: 'space_product_tags' }) public allowedTags: NewTagEntity[]; }