mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 02:15:21 +00:00
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
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<SpaceDto> {
|
|
@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<SpaceEntity>) {
|
|
super();
|
|
Object.assign(this, partial);
|
|
}
|
|
}
|