API related changes done

This commit is contained in:
VirajBrainvire
2024-04-23 18:09:50 +05:30
parent d61a1b92e7
commit c311c51f68
2 changed files with 27 additions and 4 deletions

View File

@ -8,7 +8,7 @@ export interface GetDeviceDetailsInterface {
export interface GetDevicesByRoomIdInterface {
success: boolean;
msg: string;
result: [];
result:any;
}
export interface GetDevicesByGroupIdInterface {

View File

@ -82,7 +82,12 @@ export class DeviceService {
): Promise<GetDevicesByRoomIdInterface> {
try {
const path = `/v2.0/cloud/thing/space/device`;
const response = await this.tuya.request({
const getDeviceByRoomId = await this.deviceRepository.find({
where: {
deviceTuyaUuid: getDeviceByRoomIdDto.roomId,
},
});
const response:any = await this.tuya.request({
method: 'GET',
path,
query: {
@ -90,7 +95,26 @@ export class DeviceService {
page_size: getDeviceByRoomIdDto.pageSize,
},
});
return response as GetDevicesByRoomIdInterface;
if (!getDeviceByRoomId.length) {
throw new NotFoundException('Devices Not Found');
}
const matchingRecords = [];
getDeviceByRoomId.forEach((item1) => {
const matchingItem = response.find(
(item2) => item1.deviceTuyaUuid === item2.uuid,
);
if (matchingItem) {
matchingRecords.push({...matchingItem });
}
});
return {
success:true,
msg:'Device Tuya Details Fetched successfully',
result:matchingRecords
};
} catch (error) {
throw new HttpException(
'Error fetching devices by room from Tuya',
@ -241,7 +265,6 @@ export class DeviceService {
msg: 'Group is Added to Specific Device',
result: true,
} as addDeviceInRoomInterface;
} catch (error) {
throw new HttpException(
'Error adding device in group from Tuya',