mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 18:27:05 +00:00
Refactor device service to fetch devices by group ID
This commit is contained in:
@ -74,15 +74,19 @@ export class DeviceService {
|
||||
}
|
||||
async getDevicesByGroupId(getDeviceByGroupIdDto: GetDeviceByGroupIdDto) {
|
||||
try {
|
||||
const response = await this.getDevicesByGroupIdTuya(
|
||||
const devicesIds = await this.getDevicesByGroupIdTuya(
|
||||
getDeviceByGroupIdDto,
|
||||
);
|
||||
|
||||
const devicesDetails = await Promise.all(
|
||||
devicesIds.result.data_list.map(async (device: any) => {
|
||||
const deviceData = await this.getDevicesByDeviceId(device.dev_id);
|
||||
return deviceData.result;
|
||||
}),
|
||||
);
|
||||
return {
|
||||
success: response.success,
|
||||
devices: response.result.data_list,
|
||||
count: response.result.count,
|
||||
msg: response.msg,
|
||||
success: devicesIds.success,
|
||||
devices: devicesDetails,
|
||||
msg: devicesIds.msg,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
@ -96,12 +100,11 @@ export class DeviceService {
|
||||
getDeviceByGroupIdDto: GetDeviceByGroupIdDto,
|
||||
): Promise<GetDevicesByGroupIdInterface> {
|
||||
try {
|
||||
const path = `/v2.0/cloud/thing/group`;
|
||||
const path = `/v2.0/cloud/thing/group/${getDeviceByGroupIdDto.groupId}/devices`;
|
||||
const response = await this.tuya.request({
|
||||
method: 'GET',
|
||||
path,
|
||||
query: {
|
||||
space_id: getDeviceByGroupIdDto.groupId,
|
||||
page_size: getDeviceByGroupIdDto.pageSize,
|
||||
page_no: getDeviceByGroupIdDto.pageNo,
|
||||
},
|
||||
|
Reference in New Issue
Block a user