mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 08:04:55 +00:00
finished skip any error from tuya device
This commit is contained in:
@ -172,31 +172,40 @@ export class DeviceService {
|
||||
'permission.permissionType',
|
||||
],
|
||||
});
|
||||
const devicesData = await Promise.all(
|
||||
devices.map(async (device) => {
|
||||
const safeFetchDeviceDetails = async (device: any) => {
|
||||
try {
|
||||
const tuyaDetails = await this.getDeviceDetailsByDeviceIdTuya(
|
||||
device.deviceTuyaUuid,
|
||||
);
|
||||
|
||||
return {
|
||||
haveRoom: device.spaceDevice ? true : false,
|
||||
haveRoom: !!device.spaceDevice,
|
||||
productUuid: device.productDevice.uuid,
|
||||
productType: device.productDevice.prodType,
|
||||
permissionType: device.permission[0].permissionType.type,
|
||||
...(await this.getDeviceDetailsByDeviceIdTuya(
|
||||
device.deviceTuyaUuid,
|
||||
)),
|
||||
...tuyaDetails,
|
||||
uuid: device.uuid,
|
||||
} as GetDeviceDetailsInterface;
|
||||
}),
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Skipping device with deviceTuyaUuid: ${device.deviceTuyaUuid} due to error.`,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
const devicesData = await Promise.all(
|
||||
devices.map(safeFetchDeviceDetails),
|
||||
);
|
||||
|
||||
return devicesData;
|
||||
return devicesData.filter(Boolean); // Remove null or undefined entries
|
||||
} catch (error) {
|
||||
// Handle the error here
|
||||
console.error('Error fetching devices by user:', error);
|
||||
throw new HttpException(
|
||||
'User does not have any devices',
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async getDevicesBySpaceId(
|
||||
getDeviceBySpaceUuidDto: GetDeviceBySpaceUuidDto,
|
||||
userUuid: string,
|
||||
|
||||
Reference in New Issue
Block a user