mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 18:56:22 +00:00
removed guards
This commit is contained in:
@ -21,8 +21,6 @@ import {
|
|||||||
BatchFactoryResetDevicesDto,
|
BatchFactoryResetDevicesDto,
|
||||||
} from '../dtos/control.device.dto';
|
} from '../dtos/control.device.dto';
|
||||||
import { CheckRoomGuard } from 'src/guards/room.guard';
|
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 { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||||
import { CheckDeviceGuard } from 'src/guards/device.guard';
|
import { CheckDeviceGuard } from 'src/guards/device.guard';
|
||||||
import { SuperAdminRoleGuard } from 'src/guards/super.admin.role.guard';
|
import { SuperAdminRoleGuard } from 'src/guards/super.admin.role.guard';
|
||||||
@ -80,7 +78,7 @@ export class DeviceController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard, CheckUserHavePermission)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Get(':deviceUuid')
|
@Get(':deviceUuid')
|
||||||
async getDeviceDetailsByDeviceId(
|
async getDeviceDetailsByDeviceId(
|
||||||
@Param('deviceUuid') deviceUuid: string,
|
@Param('deviceUuid') deviceUuid: string,
|
||||||
@ -93,7 +91,7 @@ export class DeviceController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard, CheckUserHavePermission)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Get(':deviceUuid/functions')
|
@Get(':deviceUuid/functions')
|
||||||
async getDeviceInstructionByDeviceId(
|
async getDeviceInstructionByDeviceId(
|
||||||
@Param('deviceUuid') deviceUuid: string,
|
@Param('deviceUuid') deviceUuid: string,
|
||||||
@ -101,14 +99,14 @@ export class DeviceController {
|
|||||||
return await this.deviceService.getDeviceInstructionByDeviceId(deviceUuid);
|
return await this.deviceService.getDeviceInstructionByDeviceId(deviceUuid);
|
||||||
}
|
}
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard, CheckUserHavePermission)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Get(':deviceUuid/functions/status')
|
@Get(':deviceUuid/functions/status')
|
||||||
async getDevicesInstructionStatus(@Param('deviceUuid') deviceUuid: string) {
|
async getDevicesInstructionStatus(@Param('deviceUuid') deviceUuid: string) {
|
||||||
return await this.deviceService.getDevicesInstructionStatus(deviceUuid);
|
return await this.deviceService.getDevicesInstructionStatus(deviceUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard, CheckUserHaveControllablePermission)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Post(':deviceUuid/control')
|
@Post(':deviceUuid/control')
|
||||||
async controlDevice(
|
async controlDevice(
|
||||||
@Body() controlDeviceDto: ControlDeviceDto,
|
@Body() controlDeviceDto: ControlDeviceDto,
|
||||||
|
@ -569,13 +569,12 @@ export class DeviceService {
|
|||||||
async getDeviceInstructionByDeviceId(
|
async getDeviceInstructionByDeviceId(
|
||||||
deviceUuid: string,
|
deviceUuid: string,
|
||||||
): Promise<DeviceInstructionResponse> {
|
): Promise<DeviceInstructionResponse> {
|
||||||
try {
|
|
||||||
const deviceDetails = await this.getDeviceByDeviceUuid(deviceUuid);
|
const deviceDetails = await this.getDeviceByDeviceUuid(deviceUuid);
|
||||||
|
|
||||||
if (!deviceDetails) {
|
if (!deviceDetails) {
|
||||||
throw new NotFoundException('Device Not Found');
|
throw new NotFoundException('Device Not Found');
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
const response = await this.getDeviceInstructionByDeviceIdTuya(
|
const response = await this.getDeviceInstructionByDeviceIdTuya(
|
||||||
deviceDetails.deviceTuyaUuid,
|
deviceDetails.deviceTuyaUuid,
|
||||||
);
|
);
|
||||||
@ -614,12 +613,12 @@ export class DeviceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async getDevicesInstructionStatus(deviceUuid: string) {
|
async getDevicesInstructionStatus(deviceUuid: string) {
|
||||||
try {
|
|
||||||
const deviceDetails = await this.getDeviceByDeviceUuid(deviceUuid);
|
const deviceDetails = await this.getDeviceByDeviceUuid(deviceUuid);
|
||||||
|
|
||||||
if (!deviceDetails) {
|
if (!deviceDetails) {
|
||||||
throw new NotFoundException('Device Not Found');
|
throw new NotFoundException('Device Not Found');
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
const deviceStatus = await this.getDevicesInstructionStatusTuya(
|
const deviceStatus = await this.getDevicesInstructionStatusTuya(
|
||||||
deviceDetails.deviceTuyaUuid,
|
deviceDetails.deviceTuyaUuid,
|
||||||
);
|
);
|
||||||
@ -630,6 +629,7 @@ export class DeviceService {
|
|||||||
status: deviceStatus.result[0].status,
|
status: deviceStatus.result[0].status,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
'Error fetching device functions status',
|
'Error fetching device functions status',
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
@ -887,7 +887,6 @@ export class DeviceService {
|
|||||||
const spaceHierarchy = await this.getFullSpaceHierarchy(
|
const spaceHierarchy = await this.getFullSpaceHierarchy(
|
||||||
device?.spaceDevice,
|
device?.spaceDevice,
|
||||||
);
|
);
|
||||||
console.log(device.spaceDevice.community);
|
|
||||||
const orderedHierarchy = spaceHierarchy.reverse();
|
const orderedHierarchy = spaceHierarchy.reverse();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -986,7 +985,6 @@ export class DeviceService {
|
|||||||
space: SpaceEntity,
|
space: SpaceEntity,
|
||||||
): Promise<{ uuid: string; spaceName: string }[]> {
|
): Promise<{ uuid: string; spaceName: string }[]> {
|
||||||
try {
|
try {
|
||||||
console.log('Fetching hierarchy for space:', space.uuid);
|
|
||||||
|
|
||||||
// Fetch only the relevant spaces, starting with the target space
|
// Fetch only the relevant spaces, starting with the target space
|
||||||
const targetSpace = await this.spaceRepository.findOne({
|
const targetSpace = await this.spaceRepository.findOne({
|
||||||
|
@ -19,6 +19,7 @@ export class GroupController {
|
|||||||
async getGroupsBySpaceUuid(@Param('spaceUuid') spaceUuid: string) {
|
async getGroupsBySpaceUuid(@Param('spaceUuid') spaceUuid: string) {
|
||||||
return await this.groupService.getGroupsByUnitUuid(spaceUuid);
|
return await this.groupService.getGroupsByUnitUuid(spaceUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Get(':unitUuid/devices/:groupName')
|
@Get(':unitUuid/devices/:groupName')
|
||||||
|
@ -31,10 +31,8 @@ export class GroupService {
|
|||||||
try {
|
try {
|
||||||
const spaces = await this.spaceRepository.find({
|
const spaces = await this.spaceRepository.find({
|
||||||
where: {
|
where: {
|
||||||
parent: {
|
|
||||||
uuid: unitUuid,
|
uuid: unitUuid,
|
||||||
},
|
},
|
||||||
},
|
|
||||||
relations: ['devices', 'devices.productDevice'],
|
relations: ['devices', 'devices.productDevice'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -155,11 +155,9 @@ export class SubspaceDeviceService {
|
|||||||
deviceId: string,
|
deviceId: string,
|
||||||
): Promise<GetDeviceDetailsInterface> {
|
): Promise<GetDeviceDetailsInterface> {
|
||||||
try {
|
try {
|
||||||
// Fetch details from TuyaService
|
|
||||||
const tuyaDeviceDetails =
|
const tuyaDeviceDetails =
|
||||||
await this.tuyaService.getDeviceDetails(deviceId);
|
await this.tuyaService.getDeviceDetails(deviceId);
|
||||||
|
|
||||||
// Convert keys to camel case
|
|
||||||
const camelCaseResponse = convertKeysToCamelCase(tuyaDeviceDetails);
|
const camelCaseResponse = convertKeysToCamelCase(tuyaDeviceDetails);
|
||||||
|
|
||||||
const product = await this.productRepository.findOne({
|
const product = await this.productRepository.findOne({
|
||||||
@ -168,8 +166,7 @@ export class SubspaceDeviceService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Exclude specific keys and add `productUuid`
|
const { uuid, ...rest } = camelCaseResponse;
|
||||||
const { ...rest } = camelCaseResponse;
|
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
productUuid: product?.uuid,
|
productUuid: product?.uuid,
|
||||||
|
Reference in New Issue
Block a user