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) {
|
async getDevicesByGroupId(getDeviceByGroupIdDto: GetDeviceByGroupIdDto) {
|
||||||
try {
|
try {
|
||||||
const response = await this.getDevicesByGroupIdTuya(
|
const devicesIds = await this.getDevicesByGroupIdTuya(
|
||||||
getDeviceByGroupIdDto,
|
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 {
|
return {
|
||||||
success: response.success,
|
success: devicesIds.success,
|
||||||
devices: response.result.data_list,
|
devices: devicesDetails,
|
||||||
count: response.result.count,
|
msg: devicesIds.msg,
|
||||||
msg: response.msg,
|
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
@ -96,12 +100,11 @@ export class DeviceService {
|
|||||||
getDeviceByGroupIdDto: GetDeviceByGroupIdDto,
|
getDeviceByGroupIdDto: GetDeviceByGroupIdDto,
|
||||||
): Promise<GetDevicesByGroupIdInterface> {
|
): Promise<GetDevicesByGroupIdInterface> {
|
||||||
try {
|
try {
|
||||||
const path = `/v2.0/cloud/thing/group`;
|
const path = `/v2.0/cloud/thing/group/${getDeviceByGroupIdDto.groupId}/devices`;
|
||||||
const response = await this.tuya.request({
|
const response = await this.tuya.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path,
|
path,
|
||||||
query: {
|
query: {
|
||||||
space_id: getDeviceByGroupIdDto.groupId,
|
|
||||||
page_size: getDeviceByGroupIdDto.pageSize,
|
page_size: getDeviceByGroupIdDto.pageSize,
|
||||||
page_no: getDeviceByGroupIdDto.pageNo,
|
page_no: getDeviceByGroupIdDto.pageNo,
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user