mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 19:24:54 +00:00
finished 4scene configration endpoints
This commit is contained in:
@ -1,4 +1,12 @@
|
||||
import { Column, Entity, ManyToOne, OneToMany, Unique, Index, JoinColumn } from 'typeorm';
|
||||
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';
|
||||
@ -6,6 +14,7 @@ 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'])
|
||||
@ -62,6 +71,9 @@ export class DeviceEntity extends AbstractEntity<DeviceDto> {
|
||||
@Column({ nullable: false })
|
||||
uuid: string;
|
||||
|
||||
@OneToMany(() => SceneDeviceEntity, (sceneDevice) => sceneDevice.device, {})
|
||||
sceneDevices: SceneDeviceEntity[];
|
||||
|
||||
constructor(partial: Partial<DeviceEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
|
||||
1
libs/common/src/modules/scene-device/dtos/index.ts
Normal file
1
libs/common/src/modules/scene-device/dtos/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './scene-device.dto';
|
||||
@ -0,0 +1,20 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class SceneDeviceDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public deviceUuid: string;
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public sceneUuid: string;
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public switchName: string;
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public automationTuyaUuid: string;
|
||||
}
|
||||
1
libs/common/src/modules/scene-device/entities/index.ts
Normal file
1
libs/common/src/modules/scene-device/entities/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './scene-device.entity';
|
||||
@ -0,0 +1,50 @@
|
||||
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
|
||||
import { SceneDeviceDto } from '../dtos';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { FourSceneSwitchesEnum } from '@app/common/constants/four-scene.enum';
|
||||
import { DeviceEntity } from '../../device/entities';
|
||||
import { SceneEntity } from '../../scene/entities';
|
||||
|
||||
@Entity({ name: 'scene-device' })
|
||||
export class SceneDeviceEntity extends AbstractEntity<SceneDeviceDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@ManyToOne(() => DeviceEntity, (device) => device.sceneDevices, {
|
||||
nullable: false,
|
||||
})
|
||||
@JoinColumn({ name: 'device_uuid' })
|
||||
device: DeviceEntity;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
sceneUuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
type: 'enum',
|
||||
enum: FourSceneSwitchesEnum,
|
||||
})
|
||||
switchName: FourSceneSwitchesEnum;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
automationTuyaUuid: string;
|
||||
|
||||
@ManyToOne(() => SceneEntity, (scene) => scene.sceneDevices, {
|
||||
nullable: false,
|
||||
})
|
||||
@JoinColumn({ name: 'scene_uuid' })
|
||||
scene: SceneEntity;
|
||||
|
||||
constructor(partial: Partial<SceneDeviceEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
export * from './scene-device.repository';
|
||||
@ -0,0 +1,10 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { SceneDeviceEntity } from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class SceneDeviceRepository extends Repository<SceneDeviceEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(SceneDeviceEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { SceneDeviceEntity } from './entities';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([SceneDeviceEntity])],
|
||||
})
|
||||
export class SceneDeviceRepositoryModule {}
|
||||
@ -2,6 +2,7 @@ import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
|
||||
import { SceneDto, SceneIconDto } from '../dtos';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { SceneIconType } from '@app/common/constants/secne-icon-type.enum';
|
||||
import { SceneDeviceEntity } from '../../scene-device/entities';
|
||||
|
||||
// Define SceneIconEntity before SceneEntity
|
||||
@Entity({ name: 'scene-icon' })
|
||||
@ -59,6 +60,9 @@ export class SceneEntity extends AbstractEntity<SceneDto> {
|
||||
})
|
||||
sceneIcon: SceneIconEntity;
|
||||
|
||||
@OneToMany(() => SceneDeviceEntity, (sceneDevice) => sceneDevice.scene)
|
||||
sceneDevices: SceneDeviceEntity[];
|
||||
|
||||
constructor(partial: Partial<SceneEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
|
||||
Reference in New Issue
Block a user