finshed get devices by room id

This commit is contained in:
faris Aljohari
2024-03-13 11:17:22 +03:00
parent dce87ac2b6
commit 5f18d1f4d5
12 changed files with 473 additions and 0 deletions

View File

@ -0,0 +1,91 @@
import { DeviceService } from '../services/device.service';
import {
Body,
Controller,
Get,
Post,
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 { ControlDeviceDto } from '../dtos/control.device.dto';
import { RenameDeviceDto } from '../dtos/rename.device.dto copy';
@ApiTags('Device Module')
@Controller({
version: '1',
path: 'device',
})
export class DeviceController {
constructor(private readonly deviceService: DeviceService) {}
// @ApiBearerAuth()
// @UseGuards(JwtAuthGuard)
@Get('room')
async getDevicesByRoomId(@Query() getDevicesDto: GetDeviceDto) {
try {
return await this.deviceService.getDevicesByRoomId(getDevicesDto);
} catch (err) {
throw new Error(err);
}
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get(':deviceId')
async getDevicesByDeviceId(@Param('deviceId') deviceId: number) {
try {
return await this.deviceService.getDevicesByDeviceId(deviceId);
} catch (err) {
throw new Error(err);
}
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Post()
async addDevice(@Body() addDeviceDto: AddDeviceDto) {
try {
return await this.deviceService.addDevice(addDeviceDto);
} catch (err) {
throw new Error(err);
}
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Post('control')
async controlDevice(@Body() controlDeviceDto: ControlDeviceDto) {
try {
return await this.deviceService.controlDevice(controlDeviceDto);
} catch (err) {
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);
}
}
}