mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 02:36:19 +00:00
API related changes done
This commit is contained in:
@ -8,7 +8,7 @@ export interface GetDeviceDetailsInterface {
|
||||
export interface GetDevicesByRoomIdInterface {
|
||||
success: boolean;
|
||||
msg: string;
|
||||
result: [];
|
||||
result:any;
|
||||
}
|
||||
|
||||
export interface GetDevicesByGroupIdInterface {
|
||||
|
@ -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',
|
||||
|
Reference in New Issue
Block a user