mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-08-25 22:39:38 +00:00
62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
import { AbstractEntity } from '@app/common/modules/abstract/entities/abstract.entity';
|
|
import { DeviceEntity } from '@app/common/modules/device/entities';
|
|
import { SubspaceModelEntity } from '@app/common/modules/space-model';
|
|
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
|
|
import { SubspaceDto } from '../../dtos';
|
|
import { SpaceEntity } from '../space.entity';
|
|
import { SubspaceProductAllocationEntity } from './subspace-product-allocation.entity';
|
|
|
|
@Entity({ name: 'subspace' })
|
|
export class SubspaceEntity extends AbstractEntity<SubspaceDto> {
|
|
@Column({
|
|
type: 'uuid',
|
|
default: () => 'gen_random_uuid()',
|
|
nullable: false,
|
|
})
|
|
public uuid: string;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
})
|
|
public subspaceName: string;
|
|
|
|
@ManyToOne(() => SpaceEntity, (space) => space.subspaces, {
|
|
nullable: false,
|
|
})
|
|
@JoinColumn({ name: 'space_uuid' })
|
|
space: SpaceEntity;
|
|
|
|
@Column({
|
|
name: 'space_uuid',
|
|
})
|
|
public spaceUuid: string;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
default: false,
|
|
})
|
|
public disabled: boolean;
|
|
|
|
@OneToMany(() => DeviceEntity, (device) => device.subspace, {
|
|
nullable: true,
|
|
})
|
|
devices: DeviceEntity[];
|
|
|
|
@ManyToOne(() => SubspaceModelEntity, (model) => model.subspace, {
|
|
nullable: true,
|
|
})
|
|
subSpaceModel?: SubspaceModelEntity;
|
|
|
|
@OneToMany(
|
|
() => SubspaceProductAllocationEntity,
|
|
(allocation) => allocation.subspace,
|
|
{ cascade: true },
|
|
)
|
|
public productAllocations: SubspaceProductAllocationEntity[];
|
|
|
|
constructor(partial: Partial<SubspaceEntity>) {
|
|
super();
|
|
Object.assign(this, partial);
|
|
}
|
|
}
|