mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-14 18:05:48 +00:00
95 lines
2.2 KiB
TypeScript
95 lines
2.2 KiB
TypeScript
import {
|
|
Column,
|
|
Entity,
|
|
JoinColumn,
|
|
ManyToOne,
|
|
OneToMany,
|
|
Unique,
|
|
} from 'typeorm';
|
|
import { SpaceDto, SpaceTypeDto } 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 { SubspaceEntity } from './subspace.entity';
|
|
import { SpaceProductEntity } from './space-product.entity';
|
|
|
|
@Entity({ name: 'space-type' })
|
|
export class SpaceTypeEntity extends AbstractEntity<SpaceTypeDto> {
|
|
@Column({
|
|
type: 'uuid',
|
|
default: () => 'gen_random_uuid()',
|
|
nullable: false,
|
|
})
|
|
public uuid: string;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
})
|
|
type: string;
|
|
|
|
constructor(partial: Partial<SpaceTypeEntity>) {
|
|
super();
|
|
Object.assign(this, partial);
|
|
}
|
|
}
|
|
|
|
@Entity({ name: 'space' })
|
|
@Unique(['invitationCode'])
|
|
export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
|
@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;
|
|
|
|
@Column({
|
|
nullable: true,
|
|
})
|
|
public invitationCode: string;
|
|
@ManyToOne(() => SpaceEntity, (space) => space.children, { nullable: true })
|
|
parent: SpaceEntity;
|
|
|
|
@OneToMany(() => SpaceEntity, (space) => space.parent)
|
|
children: SpaceEntity[];
|
|
|
|
@OneToMany(() => UserSpaceEntity, (userSpace) => userSpace.space)
|
|
userSpaces: UserSpaceEntity[];
|
|
|
|
@OneToMany(() => SubspaceEntity, (subspace) => subspace.space, {
|
|
nullable: true,
|
|
})
|
|
subspaces?: SubspaceEntity[];
|
|
|
|
@OneToMany(
|
|
() => DeviceEntity,
|
|
(devicesSpaceEntity) => devicesSpaceEntity.spaceDevice,
|
|
)
|
|
devices: DeviceEntity[];
|
|
|
|
@OneToMany(() => SpaceProductEntity, (spaceProduct) => spaceProduct.space)
|
|
spaceProducts: SpaceProductEntity[];
|
|
|
|
constructor(partial: Partial<SpaceEntity>) {
|
|
super();
|
|
Object.assign(this, partial);
|
|
}
|
|
}
|