mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 20:44:53 +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,
|
||||
|
||||
@ -26,8 +26,8 @@ export class SpaceDeviceService {
|
||||
spaceUuid,
|
||||
);
|
||||
|
||||
const detailedDevices = await Promise.all(
|
||||
space.devices.map(async (device) => {
|
||||
const safeFetch = async (device: any) => {
|
||||
try {
|
||||
const tuyaDetails = await this.getDeviceDetailsByDeviceIdTuya(
|
||||
device.deviceTuyaUuid,
|
||||
);
|
||||
@ -41,11 +41,18 @@ export class SpaceDeviceService {
|
||||
updatedAt: device.updatedAt,
|
||||
...tuyaDetails,
|
||||
};
|
||||
}),
|
||||
);
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Skipping device with deviceTuyaUuid: ${device.deviceTuyaUuid} due to error.`,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const detailedDevices = await Promise.all(space.devices.map(safeFetch));
|
||||
|
||||
return new SuccessResponseDto({
|
||||
data: detailedDevices,
|
||||
data: detailedDevices.filter(Boolean), // Remove null or undefined values
|
||||
message: 'Successfully retrieved list of devices',
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
@ -33,8 +33,8 @@ export class SubspaceDeviceService {
|
||||
|
||||
const subspace = await this.findSubspaceWithDevices(subSpaceUuid);
|
||||
|
||||
const detailedDevices = await Promise.all(
|
||||
subspace.devices.map(async (device) => {
|
||||
const safeFetch = async (device: any) => {
|
||||
try {
|
||||
const tuyaDetails = await this.getDeviceDetailsByDeviceIdTuya(
|
||||
device.deviceTuyaUuid,
|
||||
);
|
||||
@ -49,11 +49,17 @@ export class SubspaceDeviceService {
|
||||
updatedAt: device.updatedAt,
|
||||
...tuyaDetails,
|
||||
};
|
||||
}),
|
||||
);
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Skipping device with deviceTuyaUuid: ${device.deviceTuyaUuid} due to error.`,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
const detailedDevices = await Promise.all(subspace.devices.map(safeFetch));
|
||||
|
||||
return new SuccessResponseDto({
|
||||
data: detailedDevices,
|
||||
data: detailedDevices.filter(Boolean), // Remove nulls
|
||||
message: 'Successfully retrieved list of devices',
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user