diff --git a/src/device/controllers/device.controller.ts b/src/device/controllers/device.controller.ts index e2aa32c..bcffdc6 100644 --- a/src/device/controllers/device.controller.ts +++ b/src/device/controllers/device.controller.ts @@ -21,8 +21,6 @@ import { BatchFactoryResetDevicesDto, } from '../dtos/control.device.dto'; import { CheckRoomGuard } from 'src/guards/room.guard'; -import { CheckUserHavePermission } from 'src/guards/user.device.permission.guard'; -import { CheckUserHaveControllablePermission } from 'src/guards/user.device.controllable.permission.guard'; import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard'; import { CheckDeviceGuard } from 'src/guards/device.guard'; import { SuperAdminRoleGuard } from 'src/guards/super.admin.role.guard'; @@ -80,7 +78,7 @@ export class DeviceController { } @ApiBearerAuth() - @UseGuards(JwtAuthGuard, CheckUserHavePermission) + @UseGuards(JwtAuthGuard) @Get(':deviceUuid') async getDeviceDetailsByDeviceId( @Param('deviceUuid') deviceUuid: string, @@ -93,7 +91,7 @@ export class DeviceController { ); } @ApiBearerAuth() - @UseGuards(JwtAuthGuard, CheckUserHavePermission) + @UseGuards(JwtAuthGuard) @Get(':deviceUuid/functions') async getDeviceInstructionByDeviceId( @Param('deviceUuid') deviceUuid: string, @@ -101,14 +99,14 @@ export class DeviceController { return await this.deviceService.getDeviceInstructionByDeviceId(deviceUuid); } @ApiBearerAuth() - @UseGuards(JwtAuthGuard, CheckUserHavePermission) + @UseGuards(JwtAuthGuard) @Get(':deviceUuid/functions/status') async getDevicesInstructionStatus(@Param('deviceUuid') deviceUuid: string) { return await this.deviceService.getDevicesInstructionStatus(deviceUuid); } @ApiBearerAuth() - @UseGuards(JwtAuthGuard, CheckUserHaveControllablePermission) + @UseGuards(JwtAuthGuard) @Post(':deviceUuid/control') async controlDevice( @Body() controlDeviceDto: ControlDeviceDto, diff --git a/src/device/services/device.service.ts b/src/device/services/device.service.ts index a93e52d..ec773ec 100644 --- a/src/device/services/device.service.ts +++ b/src/device/services/device.service.ts @@ -569,13 +569,12 @@ export class DeviceService { async getDeviceInstructionByDeviceId( deviceUuid: string, ): Promise { + const deviceDetails = await this.getDeviceByDeviceUuid(deviceUuid); + + if (!deviceDetails) { + throw new NotFoundException('Device Not Found'); + } try { - const deviceDetails = await this.getDeviceByDeviceUuid(deviceUuid); - - if (!deviceDetails) { - throw new NotFoundException('Device Not Found'); - } - const response = await this.getDeviceInstructionByDeviceIdTuya( deviceDetails.deviceTuyaUuid, ); @@ -614,12 +613,12 @@ export class DeviceService { } } async getDevicesInstructionStatus(deviceUuid: string) { - try { - const deviceDetails = await this.getDeviceByDeviceUuid(deviceUuid); + const deviceDetails = await this.getDeviceByDeviceUuid(deviceUuid); - if (!deviceDetails) { - throw new NotFoundException('Device Not Found'); - } + if (!deviceDetails) { + throw new NotFoundException('Device Not Found'); + } + try { const deviceStatus = await this.getDevicesInstructionStatusTuya( deviceDetails.deviceTuyaUuid, ); @@ -630,6 +629,7 @@ export class DeviceService { status: deviceStatus.result[0].status, }; } catch (error) { + console.log(error); throw new HttpException( 'Error fetching device functions status', HttpStatus.INTERNAL_SERVER_ERROR, @@ -887,7 +887,6 @@ export class DeviceService { const spaceHierarchy = await this.getFullSpaceHierarchy( device?.spaceDevice, ); - console.log(device.spaceDevice.community); const orderedHierarchy = spaceHierarchy.reverse(); return { @@ -986,7 +985,6 @@ export class DeviceService { space: SpaceEntity, ): Promise<{ uuid: string; spaceName: string }[]> { try { - console.log('Fetching hierarchy for space:', space.uuid); // Fetch only the relevant spaces, starting with the target space const targetSpace = await this.spaceRepository.findOne({ diff --git a/src/group/controllers/group.controller.ts b/src/group/controllers/group.controller.ts index 0c2c8b8..ed79baf 100644 --- a/src/group/controllers/group.controller.ts +++ b/src/group/controllers/group.controller.ts @@ -19,6 +19,7 @@ export class GroupController { async getGroupsBySpaceUuid(@Param('spaceUuid') spaceUuid: string) { return await this.groupService.getGroupsByUnitUuid(spaceUuid); } + @ApiBearerAuth() @UseGuards(JwtAuthGuard) @Get(':unitUuid/devices/:groupName') diff --git a/src/group/services/group.service.ts b/src/group/services/group.service.ts index d84edea..e8e39f9 100644 --- a/src/group/services/group.service.ts +++ b/src/group/services/group.service.ts @@ -31,9 +31,7 @@ export class GroupService { try { const spaces = await this.spaceRepository.find({ where: { - parent: { - uuid: unitUuid, - }, + uuid: unitUuid, }, relations: ['devices', 'devices.productDevice'], }); diff --git a/src/space/services/subspace/subspace-device.service.ts b/src/space/services/subspace/subspace-device.service.ts index b7a18b3..9b2db68 100644 --- a/src/space/services/subspace/subspace-device.service.ts +++ b/src/space/services/subspace/subspace-device.service.ts @@ -155,11 +155,9 @@ export class SubspaceDeviceService { deviceId: string, ): Promise { try { - // Fetch details from TuyaService const tuyaDeviceDetails = await this.tuyaService.getDeviceDetails(deviceId); - // Convert keys to camel case const camelCaseResponse = convertKeysToCamelCase(tuyaDeviceDetails); const product = await this.productRepository.findOne({ @@ -168,8 +166,7 @@ export class SubspaceDeviceService { }, }); - // Exclude specific keys and add `productUuid` - const { ...rest } = camelCaseResponse; + const { uuid, ...rest } = camelCaseResponse; return { ...rest, productUuid: product?.uuid,