mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 03:34:55 +00:00
finished get status for batch devices endpoint
This commit is contained in:
@ -24,6 +24,7 @@ import {
|
||||
} from '../dtos/get.device.dto';
|
||||
import {
|
||||
BatchControlDevicesDto,
|
||||
BatchStatusDevicesDto,
|
||||
ControlDeviceDto,
|
||||
} from '../dtos/control.device.dto';
|
||||
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
||||
@ -362,7 +363,29 @@ export class DeviceService {
|
||||
);
|
||||
}
|
||||
}
|
||||
async batchStatusDevices(batchStatusDevicesDto: BatchStatusDevicesDto) {
|
||||
const { devicesUuid } = batchStatusDevicesDto;
|
||||
const devicesUuidArray = devicesUuid.split(',');
|
||||
|
||||
try {
|
||||
await this.checkAllDevicesHaveSameProductUuid(devicesUuidArray);
|
||||
const statuses = await Promise.all(
|
||||
devicesUuidArray.map(async (deviceUuid) => {
|
||||
const result = await this.getDevicesInstructionStatus(deviceUuid);
|
||||
return { deviceUuid, result };
|
||||
}),
|
||||
);
|
||||
return {
|
||||
status: statuses[0].result,
|
||||
devices: statuses,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Device Not Found',
|
||||
error.status || HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
}
|
||||
async checkAllDevicesHaveSameProductUuid(deviceUuids: string[]) {
|
||||
const firstDevice = await this.deviceRepository.findOne({
|
||||
where: { uuid: deviceUuids[0] },
|
||||
|
||||
Reference in New Issue
Block a user