mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 09:54:55 +00:00
finished get all switches
This commit is contained in:
@ -231,7 +231,7 @@ export class DeviceController {
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('four-scene/:deviceUuid')
|
||||
@Get('four-scene/switch/:deviceUuid')
|
||||
async getSceneFourSceneDevice(
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Query() getSceneFourSceneDeviceDto: GetSceneFourSceneDeviceDto,
|
||||
@ -241,4 +241,10 @@ export class DeviceController {
|
||||
getSceneFourSceneDeviceDto,
|
||||
);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('four-scene/:deviceUuid')
|
||||
async getScenesFourSceneDevice(@Param('deviceUuid') deviceUuid: string) {
|
||||
return await this.deviceService.getScenesFourSceneDevice(deviceUuid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1350,4 +1350,51 @@ export class DeviceService {
|
||||
throw new HttpException('Scene device not found', HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
async getScenesFourSceneDevice(deviceUuid: string): Promise<any[]> {
|
||||
try {
|
||||
const sceneDevices = await this.sceneDeviceRepository.find({
|
||||
where: { device: { uuid: deviceUuid } },
|
||||
relations: ['device', 'scene'],
|
||||
});
|
||||
|
||||
if (!sceneDevices.length) {
|
||||
throw new HttpException(
|
||||
'No scenes found for the device',
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
const results = await Promise.all(
|
||||
sceneDevices.map(async (sceneDevice) => {
|
||||
if (!sceneDevice.scene?.uuid) return null;
|
||||
|
||||
try {
|
||||
const sceneDetails = await this.sceneService.getSceneByUuid(
|
||||
sceneDevice.scene.uuid,
|
||||
);
|
||||
|
||||
return {
|
||||
switchName: sceneDevice.switchName,
|
||||
createdAt: sceneDevice.createdAt,
|
||||
updatedAt: sceneDevice.updatedAt,
|
||||
deviceUuid: sceneDevice.device.uuid,
|
||||
scene: sceneDetails.data,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
'Failed to fetch scene details',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
return results.filter(Boolean);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Failed to fetch scenes for device',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user