mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 02:36:19 +00:00
finshed device endpoint
This commit is contained in:
@ -7,15 +7,18 @@ import {
|
||||
UseGuards,
|
||||
Query,
|
||||
Param,
|
||||
Put,
|
||||
Delete,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
|
||||
import { AddDeviceDto } from '../dtos/add.device.dto';
|
||||
import { GetDeviceDto } from '../dtos/get.device.dto';
|
||||
import {
|
||||
AddDeviceInGroupDto,
|
||||
AddDeviceInRoomDto,
|
||||
} from '../dtos/add.device.dto';
|
||||
import {
|
||||
GetDeviceByGroupIdDto,
|
||||
GetDeviceByRoomIdDto,
|
||||
} from '../dtos/get.device.dto';
|
||||
import { ControlDeviceDto } from '../dtos/control.device.dto';
|
||||
import { RenameDeviceDto } from '../dtos/rename.device.dto copy';
|
||||
|
||||
@ApiTags('Device Module')
|
||||
@Controller({
|
||||
@ -25,12 +28,28 @@ import { RenameDeviceDto } from '../dtos/rename.device.dto copy';
|
||||
export class DeviceController {
|
||||
constructor(private readonly deviceService: DeviceService) {}
|
||||
|
||||
// @ApiBearerAuth()
|
||||
// @UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('room')
|
||||
async getDevicesByRoomId(@Query() getDevicesDto: GetDeviceDto) {
|
||||
async getDevicesByRoomId(
|
||||
@Query() getDeviceByRoomIdDto: GetDeviceByRoomIdDto,
|
||||
) {
|
||||
try {
|
||||
return await this.deviceService.getDevicesByRoomId(getDevicesDto);
|
||||
return await this.deviceService.getDevicesByRoomId(getDeviceByRoomIdDto);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('group')
|
||||
async getDevicesByGroupId(
|
||||
@Query() getDeviceByGroupIdDto: GetDeviceByGroupIdDto,
|
||||
) {
|
||||
try {
|
||||
return await this.deviceService.getDevicesByGroupId(
|
||||
getDeviceByGroupIdDto,
|
||||
);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
@ -38,7 +57,7 @@ export class DeviceController {
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get(':deviceId')
|
||||
async getDevicesByDeviceId(@Param('deviceId') deviceId: number) {
|
||||
async getDevicesByDeviceId(@Param('deviceId') deviceId: string) {
|
||||
try {
|
||||
return await this.deviceService.getDevicesByDeviceId(deviceId);
|
||||
} catch (err) {
|
||||
@ -47,15 +66,44 @@ export class DeviceController {
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post()
|
||||
async addDevice(@Body() addDeviceDto: AddDeviceDto) {
|
||||
@Get(':deviceId/functions')
|
||||
async getDevicesInstructionByDeviceId(@Param('deviceId') deviceId: string) {
|
||||
try {
|
||||
return await this.deviceService.addDevice(addDeviceDto);
|
||||
return await this.deviceService.getDevicesInstructionByDeviceId(deviceId);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get(':deviceId/functions/status')
|
||||
async getDevicesInstructionStatus(@Param('deviceId') deviceId: string) {
|
||||
try {
|
||||
return await this.deviceService.getDevicesInstructionStatus(deviceId);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('room')
|
||||
async addDeviceInRoom(@Body() addDeviceInRoomDto: AddDeviceInRoomDto) {
|
||||
try {
|
||||
return await this.deviceService.addDeviceInRoom(addDeviceInRoomDto);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('group')
|
||||
async addDeviceInGroup(@Body() addDeviceInGroupDto: AddDeviceInGroupDto) {
|
||||
try {
|
||||
return await this.deviceService.addDeviceInGroup(addDeviceInGroupDto);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('control')
|
||||
@ -66,26 +114,4 @@ export class DeviceController {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put('rename')
|
||||
async renameDevice(@Body() renameDeviceDto: RenameDeviceDto) {
|
||||
try {
|
||||
return await this.deviceService.renameDevice(renameDeviceDto);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Delete(':deviceId')
|
||||
async deleteDevice(@Param('deviceId') deviceId: number) {
|
||||
try {
|
||||
return await this.deviceService.deleteDevice(deviceId);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user