mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 02:36:19 +00:00
finished 4scene configration endpoints
This commit is contained in:
@ -8,8 +8,15 @@ import config from './config';
|
||||
import { EmailService } from './util/email.service';
|
||||
import { ErrorMessageService } from 'src/error-message/error-message.service';
|
||||
import { TuyaService } from './integrations/tuya/services/tuya.service';
|
||||
import { SceneDeviceRepository } from './modules/scene-device/repositories';
|
||||
@Module({
|
||||
providers: [CommonService, EmailService, ErrorMessageService, TuyaService],
|
||||
providers: [
|
||||
CommonService,
|
||||
EmailService,
|
||||
ErrorMessageService,
|
||||
TuyaService,
|
||||
SceneDeviceRepository,
|
||||
],
|
||||
exports: [
|
||||
CommonService,
|
||||
TuyaService,
|
||||
@ -17,6 +24,7 @@ import { TuyaService } from './integrations/tuya/services/tuya.service';
|
||||
AuthModule,
|
||||
EmailService,
|
||||
ErrorMessageService,
|
||||
SceneDeviceRepository,
|
||||
],
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
|
6
libs/common/src/constants/four-scene.enum.ts
Normal file
6
libs/common/src/constants/four-scene.enum.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export enum FourSceneSwitchesEnum {
|
||||
Scene_1 = 'scene_1',
|
||||
Scene_2 = 'scene_2',
|
||||
Scene_3 = 'scene_3',
|
||||
Scene_4 = 'scene_4',
|
||||
}
|
@ -22,6 +22,7 @@ import { VisitorPasswordEntity } from '../modules/visitor-password/entities';
|
||||
import { CommunityEntity } from '../modules/community/entities';
|
||||
import { DeviceStatusLogEntity } from '../modules/device-status-log/entities';
|
||||
import { SceneEntity, SceneIconEntity } from '../modules/scene/entities';
|
||||
import { SceneDeviceEntity } from '../modules/scene-device/entities';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@ -60,6 +61,7 @@ import { SceneEntity, SceneIconEntity } from '../modules/scene/entities';
|
||||
DeviceStatusLogEntity,
|
||||
SceneEntity,
|
||||
SceneIconEntity,
|
||||
SceneDeviceEntity,
|
||||
],
|
||||
namingStrategy: new SnakeNamingStrategy(),
|
||||
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
||||
|
@ -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