mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-17 03:05:13 +00:00
API related changes done
This commit is contained in:
@ -8,7 +8,7 @@ export interface GetDeviceDetailsInterface {
|
|||||||
export interface GetDevicesByRoomIdInterface {
|
export interface GetDevicesByRoomIdInterface {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
msg: string;
|
msg: string;
|
||||||
result: [];
|
result:any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetDevicesByGroupIdInterface {
|
export interface GetDevicesByGroupIdInterface {
|
||||||
|
@ -82,7 +82,12 @@ export class DeviceService {
|
|||||||
): Promise<GetDevicesByRoomIdInterface> {
|
): Promise<GetDevicesByRoomIdInterface> {
|
||||||
try {
|
try {
|
||||||
const path = `/v2.0/cloud/thing/space/device`;
|
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',
|
method: 'GET',
|
||||||
path,
|
path,
|
||||||
query: {
|
query: {
|
||||||
@ -90,7 +95,26 @@ export class DeviceService {
|
|||||||
page_size: getDeviceByRoomIdDto.pageSize,
|
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) {
|
} catch (error) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
'Error fetching devices by room from Tuya',
|
'Error fetching devices by room from Tuya',
|
||||||
@ -241,7 +265,6 @@ export class DeviceService {
|
|||||||
msg: 'Group is Added to Specific Device',
|
msg: 'Group is Added to Specific Device',
|
||||||
result: true,
|
result: true,
|
||||||
} as addDeviceInRoomInterface;
|
} as addDeviceInRoomInterface;
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
'Error adding device in group from Tuya',
|
'Error adding device in group from Tuya',
|
||||||
|
Reference in New Issue
Block a user