mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 07:34:54 +00:00
Add method to get device by Tuya UUID and update getDevicesInGetawayTuya method
This commit is contained in:
@ -53,6 +53,14 @@ export class DeviceService {
|
||||
...(withProductDevice && { relations: ['productDevice'] }),
|
||||
});
|
||||
}
|
||||
async getDeviceByDeviceTuyaUuid(deviceTuyaUuid: string) {
|
||||
return await this.deviceRepository.findOne({
|
||||
where: {
|
||||
deviceTuyaUuid,
|
||||
},
|
||||
relations: ['productDevice'],
|
||||
});
|
||||
}
|
||||
async addDeviceUser(addDeviceDto: AddDeviceDto) {
|
||||
try {
|
||||
const device = await this.getDeviceDetailsByDeviceIdTuya(
|
||||
@ -434,19 +442,32 @@ export class DeviceService {
|
||||
deviceDetails.deviceTuyaUuid,
|
||||
);
|
||||
|
||||
const devices = await Promise.all(
|
||||
response.map(async (device: any) => {
|
||||
const deviceDetails = await this.getDeviceByDeviceTuyaUuid(device.id);
|
||||
if (deviceDetails.deviceTuyaUuid) {
|
||||
return {
|
||||
...device,
|
||||
uuid: deviceDetails.uuid,
|
||||
productUuid: deviceDetails.productDevice.uuid,
|
||||
productType: deviceDetails.productDevice.prodType,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
);
|
||||
|
||||
return {
|
||||
uuid: deviceDetails.uuid,
|
||||
productUuid: deviceDetails.productDevice.uuid,
|
||||
productType: deviceDetails.productDevice.prodType,
|
||||
device: response,
|
||||
devices: devices.filter((device) => device !== null),
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Device Not Found',
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
throw new HttpException('Device Not Found', HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
async getDevicesInGetawayTuya(
|
||||
deviceId: string,
|
||||
): Promise<GetDeviceDetailsInterface[]> {
|
||||
|
||||
Reference in New Issue
Block a user