mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 14:14:54 +00:00
Merge pull request #75 from SyncrowIOT/real-time-devices
Real time devices
This commit is contained in:
@ -0,0 +1,25 @@
|
|||||||
|
import { Controller, Post, Param } from '@nestjs/common';
|
||||||
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
|
import { AddDeviceStatusDto } from '../dtos/add.devices-status.dto';
|
||||||
|
import { DeviceStatusFirebaseService } from '../services/devices-status.service';
|
||||||
|
|
||||||
|
@ApiTags('Device Status Firebase Module')
|
||||||
|
@Controller({
|
||||||
|
version: '1',
|
||||||
|
path: 'device-status-firebase',
|
||||||
|
})
|
||||||
|
export class DeviceStatusFirebaseController {
|
||||||
|
constructor(
|
||||||
|
private readonly deviceStatusFirebaseService: DeviceStatusFirebaseService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@Post(':deviceTuyaUuid')
|
||||||
|
async addDeviceStatus(
|
||||||
|
@Param('deviceTuyaUuid') deviceTuyaUuid: string,
|
||||||
|
): Promise<AddDeviceStatusDto> {
|
||||||
|
return this.deviceStatusFirebaseService.addDeviceStatusByDeviceUuid(
|
||||||
|
deviceTuyaUuid,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { DeviceStatusFirebaseController } from './controllers/devices-status.controller';
|
||||||
|
import { DeviceStatusFirebaseService } from './services/devices-status.service';
|
||||||
|
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
providers: [DeviceStatusFirebaseService, DeviceRepository],
|
||||||
|
controllers: [DeviceStatusFirebaseController],
|
||||||
|
exports: [DeviceStatusFirebaseService],
|
||||||
|
})
|
||||||
|
export class DeviceStatusFirebaseModule {}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
import {
|
||||||
|
IsString,
|
||||||
|
IsArray,
|
||||||
|
ValidateNested,
|
||||||
|
IsNotEmpty,
|
||||||
|
IsOptional,
|
||||||
|
} from 'class-validator';
|
||||||
|
import { Type } from 'class-transformer';
|
||||||
|
|
||||||
|
class StatusDto {
|
||||||
|
@IsString()
|
||||||
|
code: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
value: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class AddDeviceStatusDto {
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
deviceUuid?: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
deviceTuyaUuid: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
productUuid?: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
productType?: string;
|
||||||
|
|
||||||
|
@IsArray()
|
||||||
|
@ValidateNested({ each: true })
|
||||||
|
@Type(() => StatusDto)
|
||||||
|
status: StatusDto[];
|
||||||
|
}
|
||||||
@ -0,0 +1,192 @@
|
|||||||
|
import {
|
||||||
|
HttpException,
|
||||||
|
HttpStatus,
|
||||||
|
Injectable,
|
||||||
|
NotFoundException,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { AddDeviceStatusDto } from '../dtos/add.devices-status.dto';
|
||||||
|
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||||
|
import { GetDeviceDetailsFunctionsStatusInterface } from 'src/device/interfaces/get.device.interface';
|
||||||
|
import { TuyaContext } from '@tuya/tuya-connector-nodejs';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
import { firebaseDataBase } from '../../firebase.config';
|
||||||
|
import { Database, DataSnapshot, get, ref, set } from 'firebase/database';
|
||||||
|
@Injectable()
|
||||||
|
export class DeviceStatusFirebaseService {
|
||||||
|
private tuya: TuyaContext;
|
||||||
|
private firebaseDb: Database;
|
||||||
|
constructor(
|
||||||
|
private readonly configService: ConfigService,
|
||||||
|
private readonly deviceRepository: DeviceRepository,
|
||||||
|
) {
|
||||||
|
const accessKey = this.configService.get<string>('auth-config.ACCESS_KEY');
|
||||||
|
const secretKey = this.configService.get<string>('auth-config.SECRET_KEY');
|
||||||
|
const tuyaEuUrl = this.configService.get<string>('tuya-config.TUYA_EU_URL');
|
||||||
|
this.tuya = new TuyaContext({
|
||||||
|
baseUrl: tuyaEuUrl,
|
||||||
|
accessKey,
|
||||||
|
secretKey,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initialize firebaseDb using firebaseDataBase function
|
||||||
|
this.firebaseDb = firebaseDataBase(this.configService);
|
||||||
|
}
|
||||||
|
async addDeviceStatusByDeviceUuid(
|
||||||
|
deviceTuyaUuid: string,
|
||||||
|
): Promise<AddDeviceStatusDto> {
|
||||||
|
try {
|
||||||
|
const device = await this.getDeviceByDeviceTuyaUuid(deviceTuyaUuid);
|
||||||
|
if (device.uuid) {
|
||||||
|
const deviceStatus = await this.getDevicesInstructionStatus(
|
||||||
|
device.uuid,
|
||||||
|
);
|
||||||
|
if (deviceStatus.productUuid) {
|
||||||
|
const deviceStatusSaved = await this.createDeviceStatusFirebase({
|
||||||
|
deviceUuid: device.uuid,
|
||||||
|
deviceTuyaUuid: deviceTuyaUuid,
|
||||||
|
status: deviceStatus.status,
|
||||||
|
productUuid: deviceStatus.productUuid,
|
||||||
|
productType: deviceStatus.productType,
|
||||||
|
});
|
||||||
|
|
||||||
|
return deviceStatusSaved;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
throw new HttpException(
|
||||||
|
'Device Tuya UUID not found',
|
||||||
|
error.status || HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async addDeviceStatusToFirebase(
|
||||||
|
addDeviceStatusDto: AddDeviceStatusDto,
|
||||||
|
): Promise<AddDeviceStatusDto | null> {
|
||||||
|
try {
|
||||||
|
const device = await this.getDeviceByDeviceTuyaUuid(
|
||||||
|
addDeviceStatusDto.deviceTuyaUuid,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (device?.uuid) {
|
||||||
|
return await this.createDeviceStatusFirebase({
|
||||||
|
deviceUuid: device.uuid,
|
||||||
|
...addDeviceStatusDto,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Return null if device not found or no UUID
|
||||||
|
return null;
|
||||||
|
} catch (error) {
|
||||||
|
// Handle the error silently, perhaps log it internally or ignore it
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async getDeviceByDeviceTuyaUuid(deviceTuyaUuid: string) {
|
||||||
|
return await this.deviceRepository.findOne({
|
||||||
|
where: {
|
||||||
|
deviceTuyaUuid,
|
||||||
|
},
|
||||||
|
relations: ['productDevice'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async getDevicesInstructionStatus(deviceUuid: string) {
|
||||||
|
try {
|
||||||
|
const deviceDetails = await this.getDeviceByDeviceUuid(deviceUuid);
|
||||||
|
|
||||||
|
if (!deviceDetails) {
|
||||||
|
throw new NotFoundException('Device Not Found');
|
||||||
|
}
|
||||||
|
const deviceStatus = await this.getDevicesInstructionStatusTuya(
|
||||||
|
deviceDetails.deviceTuyaUuid,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
productUuid: deviceDetails.productDevice.uuid,
|
||||||
|
productType: deviceDetails.productDevice.prodType,
|
||||||
|
status: deviceStatus.result[0].status,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
throw new HttpException(
|
||||||
|
'Error fetching device functions status',
|
||||||
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async getDevicesInstructionStatusTuya(
|
||||||
|
deviceUuid: string,
|
||||||
|
): Promise<GetDeviceDetailsFunctionsStatusInterface> {
|
||||||
|
try {
|
||||||
|
const path = `/v1.0/iot-03/devices/status`;
|
||||||
|
const response = await this.tuya.request({
|
||||||
|
method: 'GET',
|
||||||
|
path,
|
||||||
|
query: {
|
||||||
|
device_ids: deviceUuid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return response as GetDeviceDetailsFunctionsStatusInterface;
|
||||||
|
} catch (error) {
|
||||||
|
throw new HttpException(
|
||||||
|
'Error fetching device functions status from Tuya',
|
||||||
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async getDeviceByDeviceUuid(
|
||||||
|
deviceUuid: string,
|
||||||
|
withProductDevice: boolean = true,
|
||||||
|
) {
|
||||||
|
return await this.deviceRepository.findOne({
|
||||||
|
where: {
|
||||||
|
uuid: deviceUuid,
|
||||||
|
},
|
||||||
|
...(withProductDevice && { relations: ['productDevice'] }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async createDeviceStatusFirebase(
|
||||||
|
addDeviceStatusDto: AddDeviceStatusDto,
|
||||||
|
): Promise<any> {
|
||||||
|
const dataRef = ref(
|
||||||
|
this.firebaseDb,
|
||||||
|
`device-status/${addDeviceStatusDto.deviceUuid}`,
|
||||||
|
);
|
||||||
|
const snapshot: DataSnapshot = await get(dataRef);
|
||||||
|
const existingData = snapshot.val() || {};
|
||||||
|
|
||||||
|
// Assign default values if fields are not present
|
||||||
|
if (!existingData.deviceTuyaUuid) {
|
||||||
|
existingData.deviceTuyaUuid = addDeviceStatusDto.deviceTuyaUuid;
|
||||||
|
}
|
||||||
|
if (!existingData.productUuid) {
|
||||||
|
existingData.productUuid = addDeviceStatusDto.productUuid;
|
||||||
|
}
|
||||||
|
if (!existingData.productType) {
|
||||||
|
existingData.productType = addDeviceStatusDto.productType;
|
||||||
|
}
|
||||||
|
if (!existingData.status) {
|
||||||
|
existingData.status = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a map to track existing status codes
|
||||||
|
const statusMap = new Map(
|
||||||
|
existingData.status.map((item) => [item.code, item.value]),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Update or add status codes
|
||||||
|
for (const statusItem of addDeviceStatusDto.status) {
|
||||||
|
statusMap.set(statusItem.code, statusItem.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the map back to an array format
|
||||||
|
existingData.status = Array.from(statusMap, ([code, value]) => ({
|
||||||
|
code,
|
||||||
|
value,
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Save the updated data to Firebase
|
||||||
|
await set(dataRef, existingData);
|
||||||
|
|
||||||
|
// Return the updated data
|
||||||
|
return existingData;
|
||||||
|
}
|
||||||
|
}
|
||||||
24
libs/common/src/firebase/firebase.config.ts
Normal file
24
libs/common/src/firebase/firebase.config.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { initializeApp } from 'firebase/app';
|
||||||
|
import { getDatabase } from 'firebase/database';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
|
||||||
|
export const initializeFirebaseApp = (configService: ConfigService) => {
|
||||||
|
const firebaseConfig = {
|
||||||
|
apiKey: configService.get<string>('FIREBASE_API_KEY'),
|
||||||
|
authDomain: configService.get<string>('FIREBASE_AUTH_DOMAIN'),
|
||||||
|
projectId: configService.get<string>('FIREBASE_PROJECT_ID'),
|
||||||
|
storageBucket: configService.get<string>('FIREBASE_STORAGE_BUCKET'),
|
||||||
|
messagingSenderId: configService.get<string>(
|
||||||
|
'FIREBASE_MESSAGING_SENDER_ID',
|
||||||
|
),
|
||||||
|
appId: configService.get<string>('FIREBASE_APP_ID'),
|
||||||
|
measurementId: configService.get<string>('FIREBASE_MEASUREMENT_ID'),
|
||||||
|
databaseURL: configService.get<string>('FIREBASE_DATABASE_URL'),
|
||||||
|
};
|
||||||
|
|
||||||
|
const app = initializeApp(firebaseConfig);
|
||||||
|
return getDatabase(app);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const firebaseDataBase = (configService: ConfigService) =>
|
||||||
|
initializeFirebaseApp(configService);
|
||||||
9
libs/common/src/firebase/firebase.shared.module.ts
Normal file
9
libs/common/src/firebase/firebase.shared.module.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { DeviceStatusFirebaseModule } from './devices-status/devices-status.module';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [DeviceStatusFirebaseModule],
|
||||||
|
providers: [],
|
||||||
|
exports: [],
|
||||||
|
})
|
||||||
|
export class FirebaseSharedModule {}
|
||||||
@ -9,6 +9,7 @@ import { OneSignalService } from './services/onesignal.service';
|
|||||||
import { DeviceMessagesService } from './services/device.messages.service';
|
import { DeviceMessagesService } from './services/device.messages.service';
|
||||||
import { DeviceRepositoryModule } from '../modules/device/device.repository.module';
|
import { DeviceRepositoryModule } from '../modules/device/device.repository.module';
|
||||||
import { DeviceNotificationRepository } from '../modules/device/repositories';
|
import { DeviceNotificationRepository } from '../modules/device/repositories';
|
||||||
|
import { DeviceStatusFirebaseModule } from '../firebase/devices-status/devices-status.module';
|
||||||
|
|
||||||
@Global()
|
@Global()
|
||||||
@Module({
|
@Module({
|
||||||
@ -23,6 +24,10 @@ import { DeviceNotificationRepository } from '../modules/device/repositories';
|
|||||||
],
|
],
|
||||||
exports: [HelperHashService, SpacePermissionService],
|
exports: [HelperHashService, SpacePermissionService],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
imports: [SpaceRepositoryModule, DeviceRepositoryModule],
|
imports: [
|
||||||
|
SpaceRepositoryModule,
|
||||||
|
DeviceRepositoryModule,
|
||||||
|
DeviceStatusFirebaseModule,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class HelperModule {}
|
export class HelperModule {}
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import TuyaWebsocket from '../../config/tuya-web-socket-config';
|
import TuyaWebsocket from '../../config/tuya-web-socket-config';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { OneSignalService } from './onesignal.service';
|
import { DeviceStatusFirebaseService } from '@app/common/firebase/devices-status/services/devices-status.service';
|
||||||
import { DeviceMessagesService } from './device.messages.service';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TuyaWebSocketService {
|
export class TuyaWebSocketService {
|
||||||
@ -10,8 +9,7 @@ export class TuyaWebSocketService {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
private readonly oneSignalService: OneSignalService,
|
private readonly deviceStatusFirebaseService: DeviceStatusFirebaseService,
|
||||||
private readonly deviceMessagesService: DeviceMessagesService,
|
|
||||||
) {
|
) {
|
||||||
// Initialize the TuyaWebsocket client
|
// Initialize the TuyaWebsocket client
|
||||||
this.client = new TuyaWebsocket({
|
this.client = new TuyaWebsocket({
|
||||||
@ -39,10 +37,11 @@ export class TuyaWebSocketService {
|
|||||||
|
|
||||||
this.client.message(async (ws: WebSocket, message: any) => {
|
this.client.message(async (ws: WebSocket, message: any) => {
|
||||||
try {
|
try {
|
||||||
await this.deviceMessagesService.getDevicesUserNotifications(
|
await this.deviceStatusFirebaseService.addDeviceStatusToFirebase({
|
||||||
message.payload.data.bizData.devId,
|
deviceTuyaUuid: message.payload.data.bizData.devId,
|
||||||
message.payload.data.bizData,
|
status: message.payload.data.bizData.properties,
|
||||||
);
|
});
|
||||||
|
|
||||||
this.client.ackMessage(message.messageId);
|
this.client.ackMessage(message.messageId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error processing message:', error);
|
console.error('Error processing message:', error);
|
||||||
|
|||||||
1077
package-lock.json
generated
1077
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -37,6 +37,7 @@
|
|||||||
"class-validator": "^0.14.1",
|
"class-validator": "^0.14.1",
|
||||||
"crypto-js": "^4.2.0",
|
"crypto-js": "^4.2.0",
|
||||||
"express-rate-limit": "^7.1.5",
|
"express-rate-limit": "^7.1.5",
|
||||||
|
"firebase": "^10.12.5",
|
||||||
"helmet": "^7.1.0",
|
"helmet": "^7.1.0",
|
||||||
"ioredis": "^5.3.2",
|
"ioredis": "^5.3.2",
|
||||||
"morgan": "^1.10.0",
|
"morgan": "^1.10.0",
|
||||||
|
|||||||
@ -7,9 +7,10 @@ import { SpaceRepository } from '@app/common/modules/space/repositories';
|
|||||||
import { DeviceService } from 'src/device/services';
|
import { DeviceService } from 'src/device/services';
|
||||||
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||||
import { ProductRepository } from '@app/common/modules/product/repositories';
|
import { ProductRepository } from '@app/common/modules/product/repositories';
|
||||||
|
import { DeviceStatusFirebaseModule } from '@app/common/firebase/devices-status/devices-status.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ConfigModule, SpaceRepositoryModule],
|
imports: [ConfigModule, SpaceRepositoryModule, DeviceStatusFirebaseModule],
|
||||||
controllers: [AutomationController],
|
controllers: [AutomationController],
|
||||||
providers: [
|
providers: [
|
||||||
AutomationService,
|
AutomationService,
|
||||||
|
|||||||
@ -10,8 +10,14 @@ import { PermissionTypeRepository } from '@app/common/modules/permission/reposit
|
|||||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||||
import { DeviceUserPermissionRepository } from '@app/common/modules/device/repositories';
|
import { DeviceUserPermissionRepository } from '@app/common/modules/device/repositories';
|
||||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||||
|
import { DeviceStatusFirebaseModule } from '@app/common/firebase/devices-status/devices-status.module';
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ConfigModule, ProductRepositoryModule, DeviceRepositoryModule],
|
imports: [
|
||||||
|
ConfigModule,
|
||||||
|
ProductRepositoryModule,
|
||||||
|
DeviceRepositoryModule,
|
||||||
|
DeviceStatusFirebaseModule,
|
||||||
|
],
|
||||||
controllers: [DeviceController],
|
controllers: [DeviceController],
|
||||||
providers: [
|
providers: [
|
||||||
DeviceService,
|
DeviceService,
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import { PermissionType } from '@app/common/constants/permission-type.enum';
|
|||||||
import { In } from 'typeorm';
|
import { In } from 'typeorm';
|
||||||
import { ProductType } from '@app/common/constants/product-type.enum';
|
import { ProductType } from '@app/common/constants/product-type.enum';
|
||||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||||
|
import { DeviceStatusFirebaseService } from '@app/common/firebase/devices-status/services/devices-status.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DeviceService {
|
export class DeviceService {
|
||||||
@ -33,6 +34,7 @@ export class DeviceService {
|
|||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
private readonly deviceRepository: DeviceRepository,
|
private readonly deviceRepository: DeviceRepository,
|
||||||
private readonly productRepository: ProductRepository,
|
private readonly productRepository: ProductRepository,
|
||||||
|
private readonly deviceStatusFirebaseService: DeviceStatusFirebaseService,
|
||||||
private readonly spaceRepository: SpaceRepository,
|
private readonly spaceRepository: SpaceRepository,
|
||||||
) {
|
) {
|
||||||
const accessKey = this.configService.get<string>('auth-config.ACCESS_KEY');
|
const accessKey = this.configService.get<string>('auth-config.ACCESS_KEY');
|
||||||
@ -72,14 +74,28 @@ export class DeviceService {
|
|||||||
if (!device.productUuid) {
|
if (!device.productUuid) {
|
||||||
throw new Error('Product UUID is missing for the device.');
|
throw new Error('Product UUID is missing for the device.');
|
||||||
}
|
}
|
||||||
|
const deviceSaved = await this.deviceRepository.save({
|
||||||
return await this.deviceRepository.save({
|
|
||||||
deviceTuyaUuid: addDeviceDto.deviceTuyaUuid,
|
deviceTuyaUuid: addDeviceDto.deviceTuyaUuid,
|
||||||
productDevice: { uuid: device.productUuid },
|
productDevice: { uuid: device.productUuid },
|
||||||
user: {
|
user: {
|
||||||
uuid: addDeviceDto.userUuid,
|
uuid: addDeviceDto.userUuid,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
if (deviceSaved.uuid) {
|
||||||
|
const deviceStatus = await this.getDevicesInstructionStatus(
|
||||||
|
deviceSaved.uuid,
|
||||||
|
);
|
||||||
|
if (deviceStatus.productUuid) {
|
||||||
|
await this.deviceStatusFirebaseService.addDeviceStatusToFirebase({
|
||||||
|
deviceUuid: deviceSaved.uuid,
|
||||||
|
deviceTuyaUuid: addDeviceDto.deviceTuyaUuid,
|
||||||
|
status: deviceStatus.status,
|
||||||
|
productUuid: deviceStatus.productUuid,
|
||||||
|
productType: deviceStatus.productType,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deviceSaved;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === '23505') {
|
if (error.code === '23505') {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
|
|||||||
@ -7,9 +7,10 @@ import { SpaceRepository } from '@app/common/modules/space/repositories';
|
|||||||
import { DeviceService } from 'src/device/services';
|
import { DeviceService } from 'src/device/services';
|
||||||
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||||
import { ProductRepository } from '@app/common/modules/product/repositories';
|
import { ProductRepository } from '@app/common/modules/product/repositories';
|
||||||
|
import { DeviceStatusFirebaseModule } from '@app/common/firebase/devices-status/devices-status.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ConfigModule, SpaceRepositoryModule],
|
imports: [ConfigModule, SpaceRepositoryModule, DeviceStatusFirebaseModule],
|
||||||
controllers: [SceneController],
|
controllers: [SceneController],
|
||||||
providers: [
|
providers: [
|
||||||
SceneService,
|
SceneService,
|
||||||
|
|||||||
Reference in New Issue
Block a user