mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 18:27:05 +00:00
finished refactor devices module
This commit is contained in:
@ -6,25 +6,23 @@ import {
|
||||
Post,
|
||||
Query,
|
||||
Param,
|
||||
HttpStatus,
|
||||
UseGuards,
|
||||
Req,
|
||||
Put,
|
||||
Delete,
|
||||
Req,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||
import {
|
||||
AddDeviceDto,
|
||||
AddSceneToFourSceneDeviceDto,
|
||||
AssignDeviceToSpaceDto,
|
||||
UpdateDeviceDto,
|
||||
UpdateDeviceInSpaceDto,
|
||||
} from '../dtos/add.device.dto';
|
||||
import { GetDeviceLogsDto } from '../dtos/get.device.dto';
|
||||
import {
|
||||
ControlDeviceDto,
|
||||
BatchControlDevicesDto,
|
||||
BatchStatusDevicesDto,
|
||||
BatchFactoryResetDevicesDto,
|
||||
GetSceneFourSceneDeviceDto,
|
||||
} from '../dtos/control.device.dto';
|
||||
import { CheckRoomGuard } from 'src/guards/room.guard';
|
||||
@ -50,65 +48,35 @@ export class DeviceController {
|
||||
@Permissions('SPACE_DEVICE_ASSIGN_DEVICE_TO_SPACE')
|
||||
@Post()
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.DEVICE.ACTIONS.ADD_DEVICE_TO_USER_SUMMARY,
|
||||
description: ControllerRoute.DEVICE.ACTIONS.ADD_DEVICE_TO_USER_DESCRIPTION,
|
||||
summary: ControllerRoute.DEVICE.ACTIONS.ADD_DEVICE_SUMMARY,
|
||||
description: ControllerRoute.DEVICE.ACTIONS.ADD_DEVICE_DESCRIPTION,
|
||||
})
|
||||
async addDeviceUser(@Body() addDeviceDto: AddDeviceDto) {
|
||||
const device = await this.deviceService.addDeviceUser(addDeviceDto);
|
||||
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'device added successfully',
|
||||
data: device,
|
||||
};
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard)
|
||||
@Permissions('DEVICE_VIEW')
|
||||
@Get('user/:userUuid')
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.DEVICE.ACTIONS.GET_DEVICES_BY_USER_SUMMARY,
|
||||
description: ControllerRoute.DEVICE.ACTIONS.GET_DEVICES_BY_USER_DESCRIPTION,
|
||||
})
|
||||
async getDevicesByUser(@Param('userUuid') userUuid: string) {
|
||||
return await this.deviceService.getDevicesByUser(userUuid);
|
||||
async addNewDevice(
|
||||
@Body() addDeviceDto: AddDeviceDto,
|
||||
@Req() req: any,
|
||||
): Promise<BaseResponseDto> {
|
||||
const projectUuid = req.user.project.uuid;
|
||||
return await this.deviceService.addNewDevice(addDeviceDto, projectUuid);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard)
|
||||
@Permissions('SPACE_DEVICE_VIEW_DEVICE_IN_SPACE')
|
||||
@Get('space/:spaceUuid')
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.DEVICE.ACTIONS.GET_DEVICES_BY_SPACE_UUID_SUMMARY,
|
||||
description:
|
||||
ControllerRoute.DEVICE.ACTIONS.GET_DEVICES_BY_SPACE_UUID_DESCRIPTION,
|
||||
})
|
||||
async getDevicesByUnitId(@Param('spaceUuid') spaceUuid: string) {
|
||||
return await this.deviceService.getDevicesBySpaceUuid(spaceUuid);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard, CheckRoomGuard)
|
||||
@Permissions('SUBSPACE_DEVICE_UPDATE_DEVICE_IN_SUBSPACE')
|
||||
@Put('space')
|
||||
@Post(':deviceUuid/space/:spaceUuid')
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.DEVICE.ACTIONS.UPDATE_DEVICE_IN_ROOM_SUMMARY,
|
||||
description:
|
||||
ControllerRoute.DEVICE.ACTIONS.UPDATE_DEVICE_IN_ROOM_DESCRIPTION,
|
||||
})
|
||||
async updateDeviceInRoom(
|
||||
@Body() updateDeviceInSpaceDto: UpdateDeviceInSpaceDto,
|
||||
) {
|
||||
const device = await this.deviceService.updateDeviceInSpace(
|
||||
async transferDeviceInSpaces(
|
||||
@Param() updateDeviceInSpaceDto: AssignDeviceToSpaceDto,
|
||||
@Req() req: any,
|
||||
): Promise<BaseResponseDto> {
|
||||
const projectUuid = req.user.project.uuid;
|
||||
return await this.deviceService.transferDeviceInSpaces(
|
||||
updateDeviceInSpaceDto,
|
||||
projectUuid,
|
||||
);
|
||||
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'device updated in room successfully',
|
||||
data: device,
|
||||
};
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@ -122,11 +90,11 @@ export class DeviceController {
|
||||
async getDeviceDetailsByDeviceId(
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Req() req: any,
|
||||
) {
|
||||
const userUuid = req.user.uuid;
|
||||
): Promise<BaseResponseDto> {
|
||||
const projectUuid = req.user.project.uuid;
|
||||
return await this.deviceService.getDeviceDetailsByDeviceId(
|
||||
deviceUuid,
|
||||
userUuid,
|
||||
projectUuid,
|
||||
);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@ -140,18 +108,14 @@ export class DeviceController {
|
||||
async updateDevice(
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Body() updateDeviceDto: UpdateDeviceDto,
|
||||
) {
|
||||
const device = await this.deviceService.updateDevice(
|
||||
@Req() req: any,
|
||||
): Promise<BaseResponseDto> {
|
||||
const projectUuid = req.user.project.uuid;
|
||||
return await this.deviceService.updateDevice(
|
||||
deviceUuid,
|
||||
updateDeviceDto,
|
||||
projectUuid,
|
||||
);
|
||||
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'device updated successfully',
|
||||
data: device,
|
||||
};
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@ -165,8 +129,13 @@ export class DeviceController {
|
||||
})
|
||||
async getDeviceInstructionByDeviceId(
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Req() req: any,
|
||||
) {
|
||||
return await this.deviceService.getDeviceInstructionByDeviceId(deviceUuid);
|
||||
const projectUuid = req.user.project.uuid;
|
||||
return await this.deviceService.getDeviceInstructionByDeviceId(
|
||||
deviceUuid,
|
||||
projectUuid,
|
||||
);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard)
|
||||
@ -176,14 +145,18 @@ export class DeviceController {
|
||||
summary: ControllerRoute.DEVICE.ACTIONS.GET_DEVICE_STATUS_SUMMARY,
|
||||
description: ControllerRoute.DEVICE.ACTIONS.GET_DEVICE_STATUS_DESCRIPTION,
|
||||
})
|
||||
async getDevicesInstructionStatus(@Param('deviceUuid') deviceUuid: string) {
|
||||
return await this.deviceService.getDevicesInstructionStatus(deviceUuid);
|
||||
async getDevicesInstructionStatus(
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Req() req: any,
|
||||
): Promise<BaseResponseDto> {
|
||||
const projectUuid = req.user.project.uuid;
|
||||
return await this.deviceService.getDevicesStatus(deviceUuid, projectUuid);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard)
|
||||
@Permissions('DEVICE_SINGLE_CONTROL')
|
||||
@Post(':deviceUuid/control')
|
||||
@Post(':deviceUuid/command')
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.DEVICE.ACTIONS.CONTROL_DEVICE_SUMMARY,
|
||||
description: ControllerRoute.DEVICE.ACTIONS.CONTROL_DEVICE_DESCRIPTION,
|
||||
@ -191,8 +164,14 @@ export class DeviceController {
|
||||
async controlDevice(
|
||||
@Body() controlDeviceDto: ControlDeviceDto,
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
) {
|
||||
return await this.deviceService.controlDevice(controlDeviceDto, deviceUuid);
|
||||
@Req() req: any,
|
||||
): Promise<BaseResponseDto> {
|
||||
const projectUuid = req.user.project.uuid;
|
||||
return await this.deviceService.controlDevice(
|
||||
controlDeviceDto,
|
||||
deviceUuid,
|
||||
projectUuid,
|
||||
);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard)
|
||||
@ -206,10 +185,13 @@ export class DeviceController {
|
||||
async updateDeviceFirmware(
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Param('firmwareVersion') firmwareVersion: number,
|
||||
) {
|
||||
@Req() req: any,
|
||||
): Promise<BaseResponseDto> {
|
||||
const projectUuid = req.user.project.uuid;
|
||||
return await this.deviceService.updateDeviceFirmware(
|
||||
deviceUuid,
|
||||
firmwareVersion,
|
||||
projectUuid,
|
||||
);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@ -221,14 +203,21 @@ export class DeviceController {
|
||||
description:
|
||||
ControllerRoute.DEVICE.ACTIONS.GET_DEVICES_IN_GATEWAY_DESCRIPTION,
|
||||
})
|
||||
async getDevicesInGateway(@Param('gatewayUuid') gatewayUuid: string) {
|
||||
return await this.deviceService.getDevicesInGateway(gatewayUuid);
|
||||
async getDevicesInGateway(
|
||||
@Param('gatewayUuid') gatewayUuid: string,
|
||||
@Req() req: any,
|
||||
): Promise<BaseResponseDto> {
|
||||
const projectUuid = req.user.project.uuid;
|
||||
return await this.deviceService.getDevicesInGateway(
|
||||
gatewayUuid,
|
||||
projectUuid,
|
||||
);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard)
|
||||
@Permissions('DEVICE_VIEW')
|
||||
@Get('report-logs/:deviceUuid')
|
||||
@Get(':deviceUuid/report-logs')
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.DEVICE.ACTIONS.GET_DEVICE_LOGS_SUMMARY,
|
||||
description: ControllerRoute.DEVICE.ACTIONS.GET_DEVICE_LOGS_DESCRIPTION,
|
||||
@ -236,13 +225,19 @@ export class DeviceController {
|
||||
async getBuildingChildByUuid(
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Query() query: GetDeviceLogsDto,
|
||||
) {
|
||||
return await this.deviceService.getDeviceLogs(deviceUuid, query);
|
||||
@Req() req: any,
|
||||
): Promise<BaseResponseDto> {
|
||||
const projectUuid = req.user.project.uuid;
|
||||
return await this.deviceService.getDeviceLogs(
|
||||
deviceUuid,
|
||||
query,
|
||||
projectUuid,
|
||||
);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard)
|
||||
@Permissions('DEVICE_BATCH_CONTROL')
|
||||
@Post('control/batch')
|
||||
@Post('batch')
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.DEVICE.ACTIONS.BATCH_CONTROL_DEVICES_SUMMARY,
|
||||
description:
|
||||
@ -250,13 +245,18 @@ export class DeviceController {
|
||||
})
|
||||
async batchControlDevices(
|
||||
@Body() batchControlDevicesDto: BatchControlDevicesDto,
|
||||
@Req() req: any,
|
||||
) {
|
||||
return await this.deviceService.batchControlDevices(batchControlDevicesDto);
|
||||
const projectUuid = req.user.project.uuid;
|
||||
return await this.deviceService.batchControlDevices(
|
||||
batchControlDevicesDto,
|
||||
projectUuid,
|
||||
);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard)
|
||||
@Permissions('DEVICE_BATCH_CONTROL')
|
||||
@Get('status/batch')
|
||||
@Get('batch')
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.DEVICE.ACTIONS.BATCH_STATUS_DEVICES_SUMMARY,
|
||||
description:
|
||||
@ -264,41 +264,15 @@ export class DeviceController {
|
||||
})
|
||||
async batchStatusDevices(
|
||||
@Query() batchStatusDevicesDto: BatchStatusDevicesDto,
|
||||
) {
|
||||
return await this.deviceService.batchStatusDevices(batchStatusDevicesDto);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard)
|
||||
@Permissions('DEVICE_DELETE')
|
||||
@Post('factory/reset/:deviceUuid')
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.DEVICE.ACTIONS.BATCH_FACTORY_RESET_DEVICES_SUMMARY,
|
||||
description:
|
||||
ControllerRoute.DEVICE.ACTIONS.BATCH_FACTORY_RESET_DEVICES_DESCRIPTION,
|
||||
})
|
||||
async batchFactoryResetDevices(
|
||||
@Body() batchFactoryResetDevicesDto: BatchFactoryResetDevicesDto,
|
||||
) {
|
||||
return await this.deviceService.batchFactoryResetDevices(
|
||||
batchFactoryResetDevicesDto,
|
||||
);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard)
|
||||
@Permissions('DEVICE_VIEW')
|
||||
@Get(':powerClampUuid/power-clamp/status')
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.DEVICE.ACTIONS.GET_POWER_CLAMP_STATUS_SUMMARY,
|
||||
description:
|
||||
ControllerRoute.DEVICE.ACTIONS.GET_POWER_CLAMP_STATUS_DESCRIPTION,
|
||||
})
|
||||
async getPowerClampInstructionStatus(
|
||||
@Param('powerClampUuid') powerClampUuid: string,
|
||||
) {
|
||||
return await this.deviceService.getPowerClampInstructionStatus(
|
||||
powerClampUuid,
|
||||
@Req() req: any,
|
||||
): Promise<BaseResponseDto> {
|
||||
const projectUuid = req.user.project.uuid;
|
||||
return await this.deviceService.batchStatusDevices(
|
||||
batchStatusDevicesDto,
|
||||
projectUuid,
|
||||
);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard, CheckFourAndSixSceneDeviceTypeGuard)
|
||||
@Permissions('DEVICE_SINGLE_CONTROL')
|
||||
@ -310,18 +284,14 @@ export class DeviceController {
|
||||
async addSceneToSceneDevice(
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Body() addSceneToFourSceneDeviceDto: AddSceneToFourSceneDeviceDto,
|
||||
) {
|
||||
const device = await this.deviceService.addSceneToSceneDevice(
|
||||
@Req() req: any,
|
||||
): Promise<BaseResponseDto> {
|
||||
const projectUuid = req.user.project.uuid;
|
||||
return await this.deviceService.addSceneToSceneDevice(
|
||||
deviceUuid,
|
||||
addSceneToFourSceneDeviceDto,
|
||||
projectUuid,
|
||||
);
|
||||
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: `scene added successfully to device ${deviceUuid}`,
|
||||
data: device,
|
||||
};
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard, CheckFourAndSixSceneDeviceTypeGuard)
|
||||
@ -335,10 +305,13 @@ export class DeviceController {
|
||||
async getScenesBySceneDevice(
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Query() getSceneFourSceneDeviceDto: GetSceneFourSceneDeviceDto,
|
||||
) {
|
||||
@Req() req: any,
|
||||
): Promise<BaseResponseDto> {
|
||||
const projectUuid = req.user.project.uuid;
|
||||
return await this.deviceService.getScenesBySceneDevice(
|
||||
deviceUuid,
|
||||
getSceneFourSceneDeviceDto,
|
||||
projectUuid,
|
||||
);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@ -354,7 +327,13 @@ export class DeviceController {
|
||||
async deleteSceneFromSceneDevice(
|
||||
@Param() param: DeviceSceneParamDto,
|
||||
@Query() query: DeleteSceneFromSceneDeviceDto,
|
||||
@Req() req: any,
|
||||
): Promise<BaseResponseDto> {
|
||||
return await this.deviceService.deleteSceneFromSceneDevice(param, query);
|
||||
const projectUuid = req.user.project.uuid;
|
||||
return await this.deviceService.deleteSceneFromSceneDevice(
|
||||
param,
|
||||
query,
|
||||
projectUuid,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user