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