mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 20:24:54 +00:00
128 lines
3.0 KiB
TypeScript
128 lines
3.0 KiB
TypeScript
import { Column, Entity, ManyToOne, OneToMany, Unique, Index } from 'typeorm';
|
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
|
import { DeviceDto, DeviceUserPermissionDto } from '../dtos/device.dto';
|
|
import { SpaceEntity } from '../../space/entities';
|
|
import { ProductEntity } from '../../product/entities';
|
|
import { UserEntity } from '../../user/entities';
|
|
import { DeviceNotificationDto } from '../dtos';
|
|
import { PermissionTypeEntity } from '../../permission/entities';
|
|
|
|
@Entity({ name: 'device' })
|
|
@Unique(['deviceTuyaUuid'])
|
|
export class DeviceEntity extends AbstractEntity<DeviceDto> {
|
|
@Column({
|
|
nullable: false,
|
|
})
|
|
deviceTuyaUuid: string;
|
|
|
|
@Column({
|
|
nullable: true,
|
|
default: true,
|
|
})
|
|
isActive: true;
|
|
|
|
@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.devicesSpaceEntity, {
|
|
nullable: true,
|
|
})
|
|
spaceDevice: SpaceEntity;
|
|
|
|
@ManyToOne(() => ProductEntity, (product) => product.devicesProductEntity, {
|
|
nullable: false,
|
|
})
|
|
productDevice: ProductEntity;
|
|
|
|
@Index()
|
|
@Column({ nullable: false })
|
|
uuid: string;
|
|
|
|
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);
|
|
}
|
|
}
|