mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +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';
|
'Delete scenes by device uuid and switch name';
|
||||||
public static readonly DELETE_SCENES_BY_SWITCH_NAME_DESCRIPTION =
|
public static readonly DELETE_SCENES_BY_SWITCH_NAME_DESCRIPTION =
|
||||||
'This endpoint deletes all scenes associated with a specific switch device.';
|
'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 {
|
static DEVICE_COMMISSION = class {
|
||||||
|
@ -49,12 +49,12 @@ export class TuyaService {
|
|||||||
path,
|
path,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.success) {
|
// if (!response.success) {
|
||||||
throw new HttpException(
|
// throw new HttpException(
|
||||||
`Error fetching device details: ${response.msg}`,
|
// `Error fetching device details: ${response.msg}`,
|
||||||
HttpStatus.BAD_REQUEST,
|
// HttpStatus.BAD_REQUEST,
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
return response.result;
|
return response.result;
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,11 @@ export class DeviceEntity extends AbstractEntity<DeviceDto> {
|
|||||||
})
|
})
|
||||||
deviceTuyaUuid: string;
|
deviceTuyaUuid: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
deviceTuyaConstUuid: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
default: 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 {
|
import {
|
||||||
Body,
|
Body,
|
||||||
Controller,
|
Controller,
|
||||||
Get,
|
|
||||||
Post,
|
|
||||||
Query,
|
|
||||||
Param,
|
|
||||||
UseGuards,
|
|
||||||
Put,
|
|
||||||
Delete,
|
Delete,
|
||||||
|
Get,
|
||||||
|
Param,
|
||||||
|
Post,
|
||||||
|
Put,
|
||||||
|
Query,
|
||||||
Req,
|
Req,
|
||||||
|
UnauthorizedException,
|
||||||
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} 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 {
|
import {
|
||||||
AddDeviceDto,
|
AddDeviceDto,
|
||||||
AddSceneToFourSceneDeviceDto,
|
AddSceneToFourSceneDeviceDto,
|
||||||
AssignDeviceToSpaceDto,
|
AssignDeviceToSpaceDto,
|
||||||
UpdateDeviceDto,
|
UpdateDeviceDto,
|
||||||
} from '../dtos/add.device.dto';
|
} from '../dtos/add.device.dto';
|
||||||
import { GetDeviceLogsDto } from '../dtos/get.device.dto';
|
|
||||||
import {
|
import {
|
||||||
ControlDeviceDto,
|
|
||||||
BatchControlDevicesDto,
|
BatchControlDevicesDto,
|
||||||
BatchStatusDevicesDto,
|
BatchStatusDevicesDto,
|
||||||
|
ControlDeviceDto,
|
||||||
GetSceneFourSceneDeviceDto,
|
GetSceneFourSceneDeviceDto,
|
||||||
} from '../dtos/control.device.dto';
|
} 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 { DeleteSceneFromSceneDeviceDto } from '../dtos/delete.device.dto';
|
||||||
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
import { DeviceSceneParamDto } from '../dtos/device.param.dto';
|
||||||
import { Permissions } from 'src/decorators/permissions.decorator';
|
import { GetDeviceLogsDto } from '../dtos/get.device.dto';
|
||||||
|
import { DeviceService } from '../services/device.service';
|
||||||
|
|
||||||
@ApiTags('Device Module')
|
@ApiTags('Device Module')
|
||||||
@Controller({
|
@Controller({
|
||||||
@ -340,4 +342,22 @@ export class DeviceController {
|
|||||||
projectUuid,
|
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