import { Column, Entity, ManyToOne, OneToMany } from 'typeorm'; import { SpaceDto } from '../dtos'; import { AbstractEntity } from '../../abstract/entities/abstract.entity'; import { SpaceTypeEntity } from '../../space-type/entities'; import { UserSpaceEntity } from '../../user-space/entities'; import { DeviceEntity } from '../../device/entities'; @Entity({ name: 'space' }) export class SpaceEntity extends AbstractEntity { @Column({ type: 'uuid', default: () => 'gen_random_uuid()', // Use gen_random_uuid() for default value nullable: false, }) public uuid: string; @Column({ nullable: false, }) public spaceName: string; @ManyToOne(() => SpaceEntity, (space) => space.children, { nullable: true }) parent: SpaceEntity; @OneToMany(() => SpaceEntity, (space) => space.parent) children: SpaceEntity[]; @ManyToOne(() => SpaceTypeEntity, (spaceType) => spaceType.spaces, { nullable: false, }) spaceType: SpaceTypeEntity; @OneToMany(() => UserSpaceEntity, (userSpace) => userSpace.space) userSpaces: UserSpaceEntity[]; @OneToMany( () => DeviceEntity, (devicesSpaceEntity) => devicesSpaceEntity.spaceDevice, ) devicesSpaceEntity: DeviceEntity[]; constructor(partial: Partial) { super(); Object.assign(this, partial); } }