import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm'; import { SpaceDto } from '../dtos'; import { AbstractEntity } from '../../abstract/entities/abstract.entity'; import { UserSpaceEntity } from '../../user/entities'; import { DeviceEntity } from '../../device/entities'; import { CommunityEntity } from '../../community/entities'; import { SpaceLinkEntity } from './space-link.entity'; import { SceneEntity } from '../../scene/entities'; import { SpaceModelEntity } from '../../space-model'; import { InviteUserSpaceEntity } from '../../Invite-user/entities'; import { SpaceProductAllocationEntity } from './space-product-allocation.entity'; import { SubspaceEntity } from './subspace/subspace.entity'; import { PresenceSensorDailySpaceEntity } from '../../presence-sensor/entities'; import { AqiSpaceDailyPollutantStatsEntity } from '../../aqi/entities'; @Entity({ name: 'space' }) export class SpaceEntity extends AbstractEntity { @Column({ type: 'uuid', default: () => 'gen_random_uuid()', nullable: false, }) public uuid: string; @Column({ nullable: true, }) public spaceTuyaUuid: string; @Column({ nullable: false, }) public spaceName: string; @ManyToOne(() => CommunityEntity, (community) => community.spaces, { nullable: false, onDelete: 'CASCADE', }) @JoinColumn({ name: 'community_id' }) community: CommunityEntity; @ManyToOne(() => SpaceEntity, (space) => space.children, { nullable: true }) parent: SpaceEntity; @OneToMany(() => SpaceEntity, (space) => space.parent, { nullable: false, onDelete: 'CASCADE', }) children: SpaceEntity[]; @OneToMany(() => UserSpaceEntity, (userSpace) => userSpace.space) userSpaces: UserSpaceEntity[]; @Column({ nullable: false, default: false, }) public disabled: boolean; @OneToMany(() => SubspaceEntity, (subspace) => subspace.space, { nullable: true, }) subspaces?: SubspaceEntity[]; // Position columns @Column({ type: 'float', nullable: false, default: 0 }) public x: number; // X coordinate for position @Column({ type: 'float', nullable: false, default: 0 }) public y: number; // Y coordinate for position @OneToMany( () => DeviceEntity, (devicesSpaceEntity) => devicesSpaceEntity.spaceDevice, ) devices: DeviceEntity[]; @OneToMany(() => SpaceLinkEntity, (connection) => connection.startSpace, { nullable: true, }) public outgoingConnections: SpaceLinkEntity[]; @OneToMany(() => SpaceLinkEntity, (connection) => connection.endSpace, { nullable: true, }) public incomingConnections: SpaceLinkEntity[]; @Column({ nullable: true, type: 'text', }) public icon: string; @OneToMany(() => SceneEntity, (scene) => scene.space) scenes: SceneEntity[]; @ManyToOne(() => SpaceModelEntity, (spaceModel) => spaceModel.spaces, { nullable: true, }) spaceModel?: SpaceModelEntity; @OneToMany( () => InviteUserSpaceEntity, (inviteUserSpace) => inviteUserSpace.space, ) invitedUsers: InviteUserSpaceEntity[]; @OneToMany( () => SpaceProductAllocationEntity, (allocation) => allocation.space, { cascade: true, }, ) public productAllocations: SpaceProductAllocationEntity[]; @OneToMany(() => PresenceSensorDailySpaceEntity, (sensor) => sensor.space) presenceSensorDaily: PresenceSensorDailySpaceEntity[]; @OneToMany(() => AqiSpaceDailyPollutantStatsEntity, (aqi) => aqi.space) aqiSensorDaily: AqiSpaceDailyPollutantStatsEntity[]; constructor(partial: Partial) { super(); Object.assign(this, partial); } }