Merge pull request #11 from SyncrowIOT/create-get-room-by-id-api

finshed get room by id api
This commit is contained in:
Ammar Qaffaf
2024-03-13 05:34:50 -04:00
committed by GitHub
3 changed files with 38 additions and 4 deletions

View File

@ -1,5 +1,13 @@
import { RoomService } from '../services/room.service';
import { Body, Controller, Get, Post, Param, UseGuards } from '@nestjs/common';
import {
Body,
Controller,
Get,
Post,
UseGuards,
Query,
Param,
} from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
import { AddRoomDto } from '../dtos/add.room.dto';
@ -14,15 +22,24 @@ export class RoomController {
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get(':homeId')
async userList(@Param('homeId') homeId: string) {
@Get()
async getRoomsByHomeId(@Query('homeId') homeId: string) {
try {
return await this.roomService.getRoomsByHomeId(homeId);
} catch (err) {
throw new Error(err);
}
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get(':roomId')
async getRoomsByRoomId(@Param('roomId') roomId: string) {
try {
return await this.roomService.getRoomsByRoomId(roomId);
} catch (err) {
throw new Error(err);
}
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Post()

View File

@ -2,6 +2,7 @@ export class GetRoomDetailsInterface {
result: {
id: string;
name: string;
root_id: string;
};
}
export class GetRoomsIdsInterface {

View File

@ -96,4 +96,20 @@ export class RoomService {
);
}
}
async getRoomsByRoomId(roomId: string) {
try {
const response = await this.getRoomDetails(roomId);
return {
homeId: response.result.root_id,
roomId: response.result.id,
roomName: response.result.name,
};
} catch (error) {
throw new HttpException(
'Error fetching rooms',
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
}