mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 07:07:21 +00:00
SP-1814: Update out-of-date device-virtual-id (#451)
* task: add a function to update device tuya id * Add Tuya const uuid to device
This commit is contained in:
@ -641,6 +641,11 @@ export class ControllerRoute {
|
||||
'Delete scenes by device uuid and switch name';
|
||||
public static readonly DELETE_SCENES_BY_SWITCH_NAME_DESCRIPTION =
|
||||
'This endpoint deletes all scenes associated with a specific switch device.';
|
||||
|
||||
public static readonly POPULATE_TUYA_CONST_UUID_SUMMARY =
|
||||
'Populate Tuya const UUID';
|
||||
public static readonly POPULATE_TUYA_CONST_UUID_DESCRIPTION =
|
||||
'This endpoint populates the Tuya const UUID for all devices.';
|
||||
};
|
||||
};
|
||||
static DEVICE_COMMISSION = class {
|
||||
|
@ -49,12 +49,12 @@ export class TuyaService {
|
||||
path,
|
||||
});
|
||||
|
||||
if (!response.success) {
|
||||
throw new HttpException(
|
||||
`Error fetching device details: ${response.msg}`,
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
// if (!response.success) {
|
||||
// throw new HttpException(
|
||||
// `Error fetching device details: ${response.msg}`,
|
||||
// HttpStatus.BAD_REQUEST,
|
||||
// );
|
||||
// }
|
||||
|
||||
return response.result;
|
||||
}
|
||||
|
@ -28,6 +28,11 @@ export class DeviceEntity extends AbstractEntity<DeviceDto> {
|
||||
})
|
||||
deviceTuyaUuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
deviceTuyaConstUuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
default: true,
|
||||
|
@ -1,39 +1,41 @@
|
||||
import { DeviceService } from '../services/device.service';
|
||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Query,
|
||||
Param,
|
||||
UseGuards,
|
||||
Put,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
Req,
|
||||
UnauthorizedException,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { Permissions } from 'src/decorators/permissions.decorator';
|
||||
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
||||
import { CheckRoomGuard } from 'src/guards/room.guard';
|
||||
import { CheckFourAndSixSceneDeviceTypeGuard } from 'src/guards/scene.device.type.guard';
|
||||
import {
|
||||
AddDeviceDto,
|
||||
AddSceneToFourSceneDeviceDto,
|
||||
AssignDeviceToSpaceDto,
|
||||
UpdateDeviceDto,
|
||||
} from '../dtos/add.device.dto';
|
||||
import { GetDeviceLogsDto } from '../dtos/get.device.dto';
|
||||
import {
|
||||
ControlDeviceDto,
|
||||
BatchControlDevicesDto,
|
||||
BatchStatusDevicesDto,
|
||||
ControlDeviceDto,
|
||||
GetSceneFourSceneDeviceDto,
|
||||
} from '../dtos/control.device.dto';
|
||||
import { CheckRoomGuard } from 'src/guards/room.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
import { CheckFourAndSixSceneDeviceTypeGuard } from 'src/guards/scene.device.type.guard';
|
||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { DeviceSceneParamDto } from '../dtos/device.param.dto';
|
||||
import { DeleteSceneFromSceneDeviceDto } from '../dtos/delete.device.dto';
|
||||
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
||||
import { Permissions } from 'src/decorators/permissions.decorator';
|
||||
import { DeviceSceneParamDto } from '../dtos/device.param.dto';
|
||||
import { GetDeviceLogsDto } from '../dtos/get.device.dto';
|
||||
import { DeviceService } from '../services/device.service';
|
||||
|
||||
@ApiTags('Device Module')
|
||||
@Controller({
|
||||
@ -340,4 +342,22 @@ export class DeviceController {
|
||||
projectUuid,
|
||||
);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard)
|
||||
@Permissions('DEVICE_UPDATE')
|
||||
@Post('/populate-tuya-const-uuids')
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.DEVICE.ACTIONS.POPULATE_TUYA_CONST_UUID_SUMMARY,
|
||||
description:
|
||||
ControllerRoute.DEVICE.ACTIONS.POPULATE_TUYA_CONST_UUID_DESCRIPTION,
|
||||
})
|
||||
async populateTuyaConstUuid(@Req() req: any): Promise<void> {
|
||||
const userUuid = req['user']?.userUuid;
|
||||
const userRole = req['user']?.role;
|
||||
if (!userUuid || (userRole && userRole !== RoleType.SUPER_ADMIN)) {
|
||||
throw new UnauthorizedException('Unauthorized to perform this action');
|
||||
}
|
||||
return this.deviceService.addTuyaConstUuidToDevices();
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user