Files
backend/libs/common/src/modules/space/entities/space-product-allocation.entity.ts
2025-02-10 12:58:49 +04:00

38 lines
1.1 KiB
TypeScript

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[];
}