mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 21:14:55 +00:00
finished 4scene configration endpoints
This commit is contained in:
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 {}
|
||||
Reference in New Issue
Block a user