109 lines
3.3 KiB
TypeScript
109 lines
3.3 KiB
TypeScript
import {
|
|
Body,
|
|
ClassSerializerInterceptor,
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
ParseIntPipe,
|
|
Patch,
|
|
Post,
|
|
UseGuards,
|
|
UseInterceptors,
|
|
} from '@nestjs/common';
|
|
import {
|
|
ApiTags,
|
|
ApiSecurity,
|
|
ApiOperation,
|
|
ApiOkResponse,
|
|
ApiBody,
|
|
ApiNotFoundResponse,
|
|
} from '@nestjs/swagger';
|
|
import { User } from 'src/objects/user/user.entity';
|
|
import { LoggedInUser } from 'src/shared/decorators/user.decorator';
|
|
import { AuthGuard } from 'src/shared/guards/auth.guard';
|
|
import { AppBuildingService } from './app-building.service';
|
|
import { BuildingFloorUpdateRequestDto } from './dto/building-floor-request.dto';
|
|
import { CreateBuildingRequestDto } from './dto/buildings-create-request.dto';
|
|
import {
|
|
BuildingFloorResponseDto,
|
|
BuildingsListResponseDto,
|
|
BuildingsResponseDto,
|
|
} from './dto/buildings-response.dto';
|
|
|
|
@Controller({
|
|
path: 'buildings',
|
|
})
|
|
@ApiTags('buildings')
|
|
@ApiSecurity('Bearer token')
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
@UseGuards(AuthGuard)
|
|
export class AppBuildingController {
|
|
constructor(private readonly service: AppBuildingService) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'Get buildings' })
|
|
@ApiOkResponse({ isArray: true, type: BuildingsListResponseDto })
|
|
async getBuildings(
|
|
@LoggedInUser() user: User,
|
|
): Promise<BuildingsListResponseDto[]> {
|
|
return this.service.getUserBuildings(user);
|
|
}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: 'Create building' })
|
|
@ApiNotFoundResponse({ description: 'Invalid group ID' })
|
|
@ApiBody({ type: CreateBuildingRequestDto })
|
|
@ApiOkResponse({ type: BuildingsResponseDto })
|
|
async createBuilding(
|
|
@LoggedInUser() user: User,
|
|
@Body() body: CreateBuildingRequestDto,
|
|
): Promise<BuildingsResponseDto> {
|
|
return this.service.createBuilding(user, body);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: 'Get building by ID' })
|
|
@ApiNotFoundResponse({ description: 'Building not found' })
|
|
@ApiOkResponse({ type: BuildingsResponseDto })
|
|
async getBuildingById(
|
|
@Param('id', ParseIntPipe) id: number,
|
|
@LoggedInUser() user: User,
|
|
): Promise<BuildingsResponseDto> {
|
|
return this.service.getBuildingById(user, id);
|
|
}
|
|
|
|
@Get(':id/floors')
|
|
@ApiOperation({ summary: 'Get building floors by ID' })
|
|
@ApiOkResponse({ type: BuildingFloorResponseDto, isArray: true })
|
|
async getBuildingFloorsById(
|
|
@Param('id', ParseIntPipe) id: number,
|
|
@LoggedInUser() user: User,
|
|
): Promise<BuildingFloorResponseDto[]> {
|
|
return this.service.getBuildingFloors(user, id);
|
|
}
|
|
|
|
@Get(':id/floors/:number')
|
|
@ApiOperation({ summary: 'Get building floors by ID' })
|
|
@ApiOkResponse({ type: BuildingFloorResponseDto })
|
|
async getBuildingFloorByIdByNumber(
|
|
@Param('id', ParseIntPipe) id: number,
|
|
@Param('number', ParseIntPipe) floor: number,
|
|
@LoggedInUser() user: User,
|
|
): Promise<BuildingFloorResponseDto> {
|
|
return this.service.getBuildingFloor(user, id, floor);
|
|
}
|
|
|
|
@Patch(':id/floors/:number')
|
|
@ApiBody({ type: BuildingFloorUpdateRequestDto })
|
|
@ApiOperation({ summary: 'Update building floor' })
|
|
@ApiOkResponse({ type: BuildingFloorResponseDto })
|
|
async updateBuildingFloorByIdByNumber(
|
|
@Param('id', ParseIntPipe) id: number,
|
|
@Param('number', ParseIntPipe) floor: number,
|
|
@Body() body: BuildingFloorUpdateRequestDto,
|
|
@LoggedInUser() user: User,
|
|
): Promise<BuildingFloorResponseDto> {
|
|
return this.service.updateBuildingFloor(user, body, id, floor);
|
|
}
|
|
}
|