mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 02:15:21 +00:00
Refactor Device Module
This commit is contained in:
@ -1,26 +1,19 @@
|
||||
import { Column, Entity, OneToMany } from 'typeorm';
|
||||
import { Column, Entity, ManyToOne, OneToMany, Unique } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { DeviceDto } from '../dtos/device.dto';
|
||||
import { DeviceUserPermissionEntity } from './device-user-type.entity';
|
||||
import { GroupDeviceEntity } from '../../group-device/entities';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
import { ProductEntity } from '../../product/entities';
|
||||
|
||||
@Entity({ name: 'device' })
|
||||
@Unique(['spaceDevice', 'deviceTuyaUuid'])
|
||||
export class DeviceEntity extends AbstractEntity<DeviceDto> {
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
public spaceUuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
deviceTuyaUuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
public productUuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
default: true,
|
||||
@ -44,6 +37,15 @@ export class DeviceEntity extends AbstractEntity<DeviceDto> {
|
||||
)
|
||||
userGroupDevices: GroupDeviceEntity[];
|
||||
|
||||
@ManyToOne(() => SpaceEntity, (space) => space.devicesSpaceEntity, {
|
||||
nullable: false,
|
||||
})
|
||||
spaceDevice: SpaceEntity;
|
||||
|
||||
@ManyToOne(() => ProductEntity, (product) => product.devicesProductEntity, {
|
||||
nullable: false,
|
||||
})
|
||||
productDevice: ProductEntity;
|
||||
constructor(partial: Partial<DeviceEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
|
Reference in New Issue
Block a user