mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-14 18:05:48 +00:00
147 lines
3.4 KiB
TypeScript
147 lines
3.4 KiB
TypeScript
import {
|
|
Column,
|
|
Entity,
|
|
ManyToOne,
|
|
OneToMany,
|
|
Unique,
|
|
Index,
|
|
JoinColumn,
|
|
} from 'typeorm';
|
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
|
import { DeviceDto, DeviceUserPermissionDto } from '../dtos/device.dto';
|
|
import { SpaceEntity, SubspaceEntity } from '../../space/entities';
|
|
import { ProductEntity } from '../../product/entities';
|
|
import { UserEntity } from '../../user/entities';
|
|
import { DeviceNotificationDto } from '../dtos';
|
|
import { PermissionTypeEntity } from '../../permission/entities';
|
|
import { SceneDeviceEntity } from '../../scene-device/entities';
|
|
|
|
@Entity({ name: 'device' })
|
|
@Unique(['deviceTuyaUuid'])
|
|
export class DeviceEntity extends AbstractEntity<DeviceDto> {
|
|
@Column({
|
|
nullable: false,
|
|
})
|
|
deviceTuyaUuid: string;
|
|
|
|
@Column({
|
|
nullable: true,
|
|
default: true,
|
|
type: 'boolean',
|
|
})
|
|
isActive: boolean;
|
|
|
|
@ManyToOne(() => UserEntity, (user) => user.userSpaces, { nullable: false })
|
|
user: UserEntity;
|
|
|
|
@OneToMany(
|
|
() => DeviceUserPermissionEntity,
|
|
(permission) => permission.device,
|
|
{
|
|
nullable: true,
|
|
},
|
|
)
|
|
permission: DeviceUserPermissionEntity[];
|
|
@OneToMany(
|
|
() => DeviceNotificationEntity,
|
|
(deviceUserNotification) => deviceUserNotification.device,
|
|
{
|
|
nullable: true,
|
|
},
|
|
)
|
|
deviceUserNotification: DeviceNotificationEntity[];
|
|
|
|
@ManyToOne(() => SpaceEntity, (space) => space.devices, {
|
|
nullable: true,
|
|
})
|
|
spaceDevice: SpaceEntity;
|
|
|
|
@ManyToOne(() => ProductEntity, (product) => product.devicesProductEntity, {
|
|
nullable: false,
|
|
})
|
|
productDevice: ProductEntity;
|
|
|
|
@ManyToOne(() => SubspaceEntity, (subspace) => subspace.devices, {
|
|
nullable: true,
|
|
})
|
|
@JoinColumn({ name: 'subspace_id' })
|
|
subspace: SubspaceEntity;
|
|
|
|
@Index()
|
|
@Column({ nullable: false })
|
|
uuid: string;
|
|
|
|
@OneToMany(() => SceneDeviceEntity, (sceneDevice) => sceneDevice.device, {})
|
|
sceneDevices: SceneDeviceEntity[];
|
|
|
|
constructor(partial: Partial<DeviceEntity>) {
|
|
super();
|
|
Object.assign(this, partial);
|
|
}
|
|
}
|
|
|
|
@Entity({ name: 'device-notification' })
|
|
@Unique(['userUuid', 'deviceUuid'])
|
|
export class DeviceNotificationEntity extends AbstractEntity<DeviceNotificationDto> {
|
|
@Column({
|
|
nullable: false,
|
|
})
|
|
public userUuid: string;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
})
|
|
deviceUuid: string;
|
|
|
|
@ManyToOne(() => DeviceEntity, (device) => device.permission, {
|
|
nullable: false,
|
|
})
|
|
device: DeviceEntity;
|
|
|
|
@ManyToOne(() => UserEntity, (user) => user.userPermission, {
|
|
nullable: false,
|
|
})
|
|
user: UserEntity;
|
|
constructor(partial: Partial<DeviceNotificationEntity>) {
|
|
super();
|
|
Object.assign(this, partial);
|
|
}
|
|
}
|
|
|
|
@Entity({ name: 'device-user-permission' })
|
|
@Unique(['userUuid', 'deviceUuid'])
|
|
export class DeviceUserPermissionEntity extends AbstractEntity<DeviceUserPermissionDto> {
|
|
@Column({
|
|
nullable: false,
|
|
})
|
|
public userUuid: string;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
})
|
|
deviceUuid: string;
|
|
|
|
@ManyToOne(() => DeviceEntity, (device) => device.permission, {
|
|
nullable: false,
|
|
})
|
|
device: DeviceEntity;
|
|
|
|
@ManyToOne(
|
|
() => PermissionTypeEntity,
|
|
(permissionType) => permissionType.permission,
|
|
{
|
|
nullable: false,
|
|
},
|
|
)
|
|
permissionType: PermissionTypeEntity;
|
|
|
|
@ManyToOne(() => UserEntity, (user) => user.userPermission, {
|
|
nullable: false,
|
|
})
|
|
user: UserEntity;
|
|
constructor(partial: Partial<DeviceUserPermissionEntity>) {
|
|
super();
|
|
Object.assign(this, partial);
|
|
}
|
|
}
|