mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 18:27:05 +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 { 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 { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||||
import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
|
import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
|
||||||
import { AddRoomDto } from '../dtos/add.room.dto';
|
import { AddRoomDto } from '../dtos/add.room.dto';
|
||||||
@ -14,15 +22,24 @@ export class RoomController {
|
|||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Get(':homeId')
|
@Get()
|
||||||
async userList(@Param('homeId') homeId: string) {
|
async getRoomsByHomeId(@Query('homeId') homeId: string) {
|
||||||
try {
|
try {
|
||||||
return await this.roomService.getRoomsByHomeId(homeId);
|
return await this.roomService.getRoomsByHomeId(homeId);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(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()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Post()
|
@Post()
|
||||||
|
@ -2,6 +2,7 @@ export class GetRoomDetailsInterface {
|
|||||||
result: {
|
result: {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
root_id: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
export class GetRoomsIdsInterface {
|
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