Spaces:
Sleeping
Sleeping
| import { | |
| Controller, | |
| Get, | |
| Post, | |
| Patch, | |
| Delete, | |
| Body, | |
| Param, | |
| UseGuards, | |
| Request, | |
| HttpCode, | |
| HttpStatus, | |
| ParseUUIDPipe, | |
| } from '@nestjs/common'; | |
| import { ApiTags, ApiBearerAuth } from '@nestjs/swagger'; | |
| import { RoomsService } from './rooms.service'; | |
| import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard'; | |
| import { CreateRoomDto, UpdateRoomDto, AddRoomMemberDto } from './dto'; | |
| // Custom request interface with user | |
| interface RequestWithUser extends Request { | |
| user: { | |
| id: string; | |
| email: string; | |
| }; | |
| } | |
| ('Rooms') | |
| (JwtAuthGuard) | |
| () | |
| () | |
| export class RoomsController { | |
| constructor(private readonly roomsService: RoomsService) {} | |
| /** | |
| * POST /spaces/:spaceId/rooms | |
| * Create a new room in a space | |
| */ | |
| ('spaces/:spaceId/rooms') | |
| (HttpStatus.CREATED) | |
| async createRoom( | |
| ('spaceId') spaceId: string, | |
| () dto: CreateRoomDto, | |
| () req: RequestWithUser, | |
| ): Promise<any> { | |
| const room = await this.roomsService.createRoom(spaceId, req.user.id, dto); | |
| return { | |
| success: true, | |
| data: room, | |
| }; | |
| } | |
| /** | |
| * GET /rooms/:roomId | |
| * Get room details | |
| */ | |
| ('rooms/:roomId') | |
| (HttpStatus.OK) | |
| async getRoom( | |
| ('roomId', ParseUUIDPipe) roomId: string, | |
| () req: RequestWithUser, | |
| ): Promise<any> { | |
| const room = await this.roomsService.getRoomById(roomId, req.user.id); | |
| return { | |
| success: true, | |
| data: room, | |
| }; | |
| } | |
| /** | |
| * PATCH /rooms/:roomId | |
| * Update room | |
| */ | |
| ('rooms/:roomId') | |
| (HttpStatus.OK) | |
| async updateRoom( | |
| ('roomId') roomId: string, | |
| () dto: UpdateRoomDto, | |
| () req: RequestWithUser, | |
| ): Promise<any> { | |
| const room = await this.roomsService.updateRoom(roomId, req.user.id, dto); | |
| return { | |
| success: true, | |
| data: room, | |
| }; | |
| } | |
| /** | |
| * DELETE /rooms/:roomId | |
| * Delete room | |
| */ | |
| ('rooms/:roomId') | |
| (HttpStatus.OK) | |
| async deleteRoom( | |
| ('roomId') roomId: string, | |
| () req: RequestWithUser, | |
| ): Promise<any> { | |
| await this.roomsService.deleteRoom(roomId, req.user.id); | |
| return { | |
| success: true, | |
| message: 'Room deleted successfully', | |
| }; | |
| } | |
| /** | |
| * GET /spaces/:spaceId/rooms | |
| * Get all rooms in a space | |
| */ | |
| ('spaces/:spaceId/rooms') | |
| (HttpStatus.OK) | |
| async getSpaceRooms( | |
| ('spaceId') spaceId: string, | |
| () req: RequestWithUser, | |
| ): Promise<any> { | |
| const rooms = await this.roomsService.getSpaceRooms(spaceId, req.user.id); | |
| return { | |
| success: true, | |
| data: rooms, | |
| }; | |
| } | |
| /** | |
| * GET /rooms/:roomId/members | |
| * Get room members | |
| */ | |
| ('rooms/:roomId/members') | |
| (HttpStatus.OK) | |
| async getRoomMembers( | |
| ('roomId', ParseUUIDPipe) roomId: string, | |
| () req: RequestWithUser, | |
| ): Promise<any> { | |
| const members = await this.roomsService.getRoomMembers(roomId, req.user.id); | |
| return { | |
| success: true, | |
| data: members, | |
| }; | |
| } | |
| /** | |
| * POST /rooms/:roomId/members | |
| * Add member to room | |
| */ | |
| ('rooms/:roomId/members') | |
| (HttpStatus.CREATED) | |
| async addRoomMember( | |
| ('roomId', ParseUUIDPipe) roomId: string, | |
| () dto: AddRoomMemberDto, | |
| () req: RequestWithUser, | |
| ): Promise<any> { | |
| // Get room to find space_id | |
| const room = await this.roomsService.getRoomById(roomId); | |
| await this.roomsService.addRoomMember( | |
| roomId, | |
| room.space_id, | |
| req.user.id, | |
| dto, | |
| ); | |
| return { | |
| success: true, | |
| message: 'Member added successfully', | |
| }; | |
| } | |
| /** | |
| * DELETE /rooms/:roomId/members/:userId | |
| * Remove member from room | |
| */ | |
| ('rooms/:roomId/members/:userId') | |
| (HttpStatus.OK) | |
| async removeRoomMember( | |
| ('roomId', ParseUUIDPipe) roomId: string, | |
| ('userId', ParseUUIDPipe) userId: string, | |
| () req: RequestWithUser, | |
| ): Promise<any> { | |
| await this.roomsService.removeRoomMember(roomId, userId, req.user.id); | |
| return { | |
| success: true, | |
| message: 'Member removed successfully', | |
| }; | |
| } | |
| /** | |
| * GET /rooms/:roomId/stats | |
| * Get room statistics | |
| */ | |
| ('rooms/:roomId/stats') | |
| (HttpStatus.OK) | |
| async getRoomStats( | |
| ('roomId', ParseUUIDPipe) roomId: string, | |
| () req: RequestWithUser, | |
| ): Promise<any> { | |
| const stats = await this.roomsService.getRoomStats(roomId, req.user.id); | |
| return { | |
| success: true, | |
| data: stats, | |
| }; | |
| } | |
| } | |