mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 10:54:55 +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'] }),
|
...(withProductDevice && { relations: ['productDevice'] }),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
async getDeviceByDeviceTuyaUuid(deviceTuyaUuid: string) {
|
||||||
|
return await this.deviceRepository.findOne({
|
||||||
|
where: {
|
||||||
|
deviceTuyaUuid,
|
||||||
|
},
|
||||||
|
relations: ['productDevice'],
|
||||||
|
});
|
||||||
|
}
|
||||||
async addDeviceUser(addDeviceDto: AddDeviceDto) {
|
async addDeviceUser(addDeviceDto: AddDeviceDto) {
|
||||||
try {
|
try {
|
||||||
const device = await this.getDeviceDetailsByDeviceIdTuya(
|
const device = await this.getDeviceDetailsByDeviceIdTuya(
|
||||||
@ -434,19 +442,32 @@ export class DeviceService {
|
|||||||
deviceDetails.deviceTuyaUuid,
|
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 {
|
return {
|
||||||
uuid: deviceDetails.uuid,
|
uuid: deviceDetails.uuid,
|
||||||
productUuid: deviceDetails.productDevice.uuid,
|
productUuid: deviceDetails.productDevice.uuid,
|
||||||
productType: deviceDetails.productDevice.prodType,
|
productType: deviceDetails.productDevice.prodType,
|
||||||
device: response,
|
devices: devices.filter((device) => device !== null),
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new HttpException(
|
throw new HttpException('Device Not Found', HttpStatus.NOT_FOUND);
|
||||||
error.message || 'Device Not Found',
|
|
||||||
HttpStatus.NOT_FOUND,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDevicesInGetawayTuya(
|
async getDevicesInGetawayTuya(
|
||||||
deviceId: string,
|
deviceId: string,
|
||||||
): Promise<GetDeviceDetailsInterface[]> {
|
): Promise<GetDeviceDetailsInterface[]> {
|
||||||
|
|||||||
Reference in New Issue
Block a user