mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 18:56:22 +00:00
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { Column, Entity, ManyToOne, JoinColumn, OneToMany } from 'typeorm';
|
|
import { SpaceEntity } from './space.entity';
|
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
|
import { ProductEntity } from '../../product/entities';
|
|
import { SpaceProductItemEntity } from './space-product-item.entity';
|
|
import { SpaceProductModelEntity } from '../../space-model';
|
|
|
|
@Entity({ name: 'space-product' })
|
|
export class SpaceProductEntity extends AbstractEntity<SpaceProductEntity> {
|
|
@ManyToOne(() => SpaceEntity, (space) => space.spaceProducts, {
|
|
nullable: false,
|
|
onDelete: 'CASCADE',
|
|
})
|
|
@JoinColumn({ name: 'space_uuid' })
|
|
space: SpaceEntity;
|
|
|
|
@ManyToOne(() => ProductEntity, (product) => product.spaceProducts, {
|
|
nullable: false,
|
|
onDelete: 'CASCADE',
|
|
})
|
|
@JoinColumn({ name: 'product_uuid' })
|
|
product: ProductEntity;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
type: 'int',
|
|
})
|
|
productCount: number;
|
|
|
|
@OneToMany(() => SpaceProductItemEntity, (item) => item.spaceProduct, {
|
|
cascade: true,
|
|
})
|
|
public items: SpaceProductItemEntity[];
|
|
|
|
@ManyToOne(
|
|
() => SpaceProductModelEntity,
|
|
(spaceProductModel) => spaceProductModel.spaceProducts,
|
|
{
|
|
nullable: true,
|
|
},
|
|
)
|
|
@JoinColumn({ name: 'space_product_model_uuid' })
|
|
public spaceProductModel?: SpaceProductModelEntity;
|
|
|
|
constructor(partial: Partial<SpaceProductEntity>) {
|
|
super();
|
|
Object.assign(this, partial);
|
|
}
|
|
}
|