mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-14 09:57:28 +00:00
Merge pull request #11 from SyncrowIOT/create-get-room-by-id-api
finshed get room by id api
This commit is contained in:
@ -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()
|
||||
|
@ -2,6 +2,7 @@ export class GetRoomDetailsInterface {
|
||||
result: {
|
||||
id: string;
|
||||
name: string;
|
||||
root_id: string;
|
||||
};
|
||||
}
|
||||
export class GetRoomsIdsInterface {
|
||||
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user