mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 08:14:55 +00:00
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
import { RoomService } from '../services/room.service';
|
|
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';
|
|
|
|
@ApiTags('Room Module')
|
|
@Controller({
|
|
version: '1',
|
|
path: 'room',
|
|
})
|
|
export class RoomController {
|
|
constructor(private readonly roomService: RoomService) {}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@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()
|
|
async addRoom(@Body() addRoomDto: AddRoomDto) {
|
|
try {
|
|
return await this.roomService.addRoom(addRoomDto);
|
|
} catch (err) {
|
|
throw new Error(err);
|
|
}
|
|
}
|
|
}
|