mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 10:25:23 +00:00
feat: add DEVICE_ADD permission and update device handling logic
This commit is contained in:
@ -9,6 +9,7 @@ export const RolePermissions = {
|
||||
'DEVICE_BATCH_CONTROL',
|
||||
'DEVICE_LOCATION_VIEW',
|
||||
'DEVICE_LOCATION_UPDATE',
|
||||
'DEVICE_ADD',
|
||||
'COMMUNITY_VIEW',
|
||||
'COMMUNITY_ADD',
|
||||
'COMMUNITY_UPDATE',
|
||||
@ -60,6 +61,7 @@ export const RolePermissions = {
|
||||
'DEVICE_VIEW',
|
||||
'DEVICE_DELETE',
|
||||
'DEVICE_UPDATE',
|
||||
'DEVICE_ADD',
|
||||
'DEVICE_BATCH_CONTROL',
|
||||
'DEVICE_LOCATION_VIEW',
|
||||
'DEVICE_LOCATION_UPDATE',
|
||||
|
@ -33,9 +33,6 @@ export class DeviceEntity extends AbstractEntity<DeviceDto> {
|
||||
})
|
||||
isActive: boolean;
|
||||
|
||||
@ManyToOne(() => UserEntity, (user) => user.userSpaces, { nullable: false })
|
||||
user: UserEntity;
|
||||
|
||||
@OneToMany(
|
||||
() => DeviceUserPermissionEntity,
|
||||
(permission) => permission.device,
|
||||
|
@ -16,7 +16,6 @@ import {
|
||||
} from '../dtos';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import {
|
||||
DeviceEntity,
|
||||
DeviceNotificationEntity,
|
||||
DeviceUserPermissionEntity,
|
||||
} from '../../device/entities';
|
||||
@ -98,9 +97,6 @@ export class UserEntity extends AbstractEntity<UserDto> {
|
||||
@OneToMany(() => UserSpaceEntity, (userSpace) => userSpace.user)
|
||||
userSpaces: UserSpaceEntity[];
|
||||
|
||||
@OneToMany(() => DeviceEntity, (userDevice) => userDevice.user)
|
||||
userDevice: DeviceEntity[];
|
||||
|
||||
@OneToMany(
|
||||
() => UserNotificationEntity,
|
||||
(userNotification) => userNotification.user,
|
||||
|
@ -26,7 +26,6 @@ import {
|
||||
GetSceneFourSceneDeviceDto,
|
||||
} from '../dtos/control.device.dto';
|
||||
import { CheckRoomGuard } from 'src/guards/room.guard';
|
||||
import { CheckDeviceGuard } from 'src/guards/device.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';
|
||||
@ -104,8 +103,8 @@ export class DeviceController {
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard, CheckDeviceGuard)
|
||||
@Permissions('SPACE_DEVICE_ASSIGN_DEVICE_TO_SPACE')
|
||||
@UseGuards(PermissionsGuard)
|
||||
@Permissions('DEVICE_ADD')
|
||||
@Post()
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.DEVICE.ACTIONS.ADD_DEVICE_SUMMARY,
|
||||
|
@ -10,6 +10,13 @@ export class AddDeviceDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public deviceTuyaUuid: string;
|
||||
@ApiProperty({
|
||||
description: 'spaceUuid',
|
||||
required: true,
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public spaceUuid: string;
|
||||
}
|
||||
export class AssignDeviceToSpaceDto {
|
||||
@ApiProperty({
|
||||
|
@ -158,6 +158,7 @@ export class DeviceService {
|
||||
const deviceSaved = await this.deviceRepository.save({
|
||||
deviceTuyaUuid: addDeviceDto.deviceTuyaUuid,
|
||||
productDevice: { uuid: device.productUuid },
|
||||
spaceDevice: { uuid: addDeviceDto.spaceUuid },
|
||||
});
|
||||
if (deviceSaved.uuid) {
|
||||
const deviceStatus: BaseResponseDto =
|
||||
|
Reference in New Issue
Block a user