Refactor device controller and service

This commit is contained in:
faris Aljohari
2024-05-30 00:18:53 +03:00
parent 6257917860
commit 45071ab927
2 changed files with 59 additions and 3 deletions

View File

@ -40,9 +40,9 @@ export class DeviceController {
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, CheckDeviceGuard)
@Post()
async addDevice(@Body() addDeviceDto: AddDeviceDto) {
async addDeviceUser(@Body() addDeviceDto: AddDeviceDto) {
try {
const device = await this.deviceService.addDevice(addDeviceDto);
const device = await this.deviceService.addDeviceUser(addDeviceDto);
return {
statusCode: HttpStatus.CREATED,
@ -58,6 +58,19 @@ export class DeviceController {
}
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get(':userUuid')
async getDevicesByUser(@Param('userUuid') userUuid: string) {
try {
return await this.deviceService.getDevicesByUser(userUuid);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, CheckRoomGuard)
@Get('room')
async getDevicesByRoomId(