delete rooms
This commit is contained in:
parent
04aa26288f
commit
6207554c99
@ -2,6 +2,7 @@ import {
|
||||
Body,
|
||||
ClassSerializerInterceptor,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
ParseIntPipe,
|
||||
@ -18,6 +19,7 @@ import {
|
||||
ApiBody,
|
||||
ApiNotFoundResponse,
|
||||
ApiParam,
|
||||
ApiNoContentResponse,
|
||||
} from '@nestjs/swagger';
|
||||
import { User } from 'src/objects/user/user.entity';
|
||||
import { LoggedInUser } from 'src/shared/decorators/user.decorator';
|
||||
@ -200,4 +202,17 @@ export class AppBuildingController {
|
||||
): Promise<BuildingRoomResponseDto> {
|
||||
return this.service.updateRoom(user, body, id, roomId);
|
||||
}
|
||||
|
||||
@Delete(':id/rooms/:roomId')
|
||||
@ApiParam({ name: 'id', description: 'Building ID' })
|
||||
@ApiParam({ name: 'roomId', description: 'Room ID' })
|
||||
@ApiOperation({ summary: 'Delete room by ID' })
|
||||
@ApiNoContentResponse()
|
||||
async deleteRoomById(
|
||||
@Param('id', ParseIntPipe) id: number,
|
||||
@Param('roomId', ParseIntPipe) roomId: number,
|
||||
@LoggedInUser() user: User,
|
||||
): Promise<BuildingRoomResponseDto> {
|
||||
return this.service.deleteRoom(user, id, roomId);
|
||||
}
|
||||
}
|
||||
|
@ -220,4 +220,20 @@ export class AppBuildingService {
|
||||
|
||||
return room;
|
||||
}
|
||||
|
||||
async deleteRoom(user: User, buildingId: number, roomId: number) {
|
||||
const room = await this.buildingService.getRoomByBuildingAndUserSub(
|
||||
buildingId,
|
||||
roomId,
|
||||
user.sub,
|
||||
);
|
||||
|
||||
if (!room) {
|
||||
throw new NotFoundException('Room not found');
|
||||
}
|
||||
|
||||
await this.buildingService.deleteRoom(room);
|
||||
|
||||
return room;
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,6 @@ async function bootstrap() {
|
||||
whitelist: true,
|
||||
}),
|
||||
);
|
||||
await app.listen(+configService.get('PORT'));
|
||||
await app.listen(+configService.get('PORT'), configService.get('HOST'));
|
||||
}
|
||||
bootstrap();
|
||||
|
@ -200,4 +200,8 @@ export class BuildingService {
|
||||
Object.assign(newRoom, data);
|
||||
return this.roomRepository.save(newRoom);
|
||||
}
|
||||
|
||||
async deleteRoom(room: Room) {
|
||||
return this.roomRepository.remove(room);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user