import { Column, Entity, ManyToOne, Unique } from 'typeorm'; import { AbstractEntity } from '../../abstract/entities/abstract.entity'; import { ProductEntity } from '../../product/entities/product.entity'; import { SpaceModelProductAllocationEntity } from '../../space-model/entities/space-model-product-allocation.entity'; import { NewTagEntity } from '../../tag/entities/tag.entity'; import { SpaceProductAllocationDto } from '../dtos/space-product-allocation.dto'; import { SpaceEntity } from './space.entity'; @Entity({ name: 'space_product_allocation' }) @Unique(['space', 'product', 'tag'], {}) export class SpaceProductAllocationEntity extends AbstractEntity { @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; @ManyToOne(() => NewTagEntity, { nullable: true, onDelete: 'CASCADE' }) public tag: NewTagEntity; constructor(partial: Partial) { super(); Object.assign(this, partial); } }