Add floor module with controller, service, DTOs, and interfaces

This commit is contained in:
faris Aljohari
2024-04-13 17:20:20 +03:00
parent 9b837bd15a
commit d5f396e4f5
11 changed files with 483 additions and 0 deletions
+102
View File
@@ -0,0 +1,102 @@
import { FloorService } from '../services/floor.service';
import {
Body,
Controller,
Get,
HttpException,
HttpStatus,
Param,
Post,
Query,
UseGuards,
} from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
import { AddFloorDto } from '../dtos/add.floor.dto';
import { GetFloorChildDto } from '../dtos/get.floor.dto';
@ApiTags('Floor Module')
@Controller({
version: '1',
path: 'floor',
})
export class FloorController {
constructor(private readonly floorService: FloorService) {}
// @ApiBearerAuth()
// @UseGuards(JwtAuthGuard)
@Post()
async addFloor(@Body() addFloorDto: AddFloorDto) {
try {
await this.floorService.addFloor(addFloorDto);
return { message: 'Floor added successfully' };
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get(':floorUuid')
async getFloorByUuid(@Param('floorUuid') floorUuid: string) {
try {
const floor = await this.floorService.getFloorByUuid(floorUuid);
return floor;
} catch (error) {
if (error.status === 404) {
throw new HttpException('Floor not found', HttpStatus.NOT_FOUND);
} else {
throw new HttpException(
error.message || 'Internal server error',
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get('child/:floorUuid')
async getFloorChildByUuid(
@Param('floorUuid') floorUuid: string,
@Query() query: GetFloorChildDto,
) {
try {
const floor = await this.floorService.getFloorChildByUuid(
floorUuid,
query,
);
return floor;
} catch (error) {
if (error.status === 404) {
throw new HttpException('Floor not found', HttpStatus.NOT_FOUND);
} else {
throw new HttpException(
error.message || 'Internal server error',
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get('parent/:floorUuid')
async getFloorParentByUuid(@Param('floorUuid') floorUuid: string) {
try {
const floor = await this.floorService.getFloorParentByUuid(floorUuid);
return floor;
} catch (error) {
if (error.status === 404) {
throw new HttpException('Floor not found', HttpStatus.NOT_FOUND);
} else {
throw new HttpException(
error.message || 'Internal server error',
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
}
}
+1
View File
@@ -0,0 +1 @@
export * from './floor.controller';