From 74b747110693e500c2a0ca0eed51095111b5cc09 Mon Sep 17 00:00:00 2001 From: faris Aljohari <83524184+farisaljohari@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:11:43 +0300 Subject: [PATCH] Refactor controllers to use userUuid as route param --- src/building/controllers/building.controller.ts | 14 ++++---------- src/building/dtos/get.building.dto.ts | 10 ---------- src/community/controllers/community.controller.ts | 14 ++++---------- src/community/dtos/get.community.dto.ts | 10 ---------- src/floor/controllers/floor.controller.ts | 9 ++++----- src/floor/dtos/get.floor.dto.ts | 10 ---------- src/room/controllers/room.controller.ts | 9 +++------ src/room/dtos/get.room.dto.ts | 12 ------------ src/unit/controllers/unit.controller.ts | 9 ++++----- 9 files changed, 19 insertions(+), 78 deletions(-) delete mode 100644 src/room/dtos/get.room.dto.ts diff --git a/src/building/controllers/building.controller.ts b/src/building/controllers/building.controller.ts index 9e7a873..bac6d18 100644 --- a/src/building/controllers/building.controller.ts +++ b/src/building/controllers/building.controller.ts @@ -10,15 +10,11 @@ import { Put, Query, UseGuards, - ValidationPipe, } from '@nestjs/common'; import { ApiTags, ApiBearerAuth } from '@nestjs/swagger'; import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard'; import { AddBuildingDto } from '../dtos/add.building.dto'; -import { - GetBuildingByUserIdDto, - GetBuildingChildDto, -} from '../dtos/get.building.dto'; +import { GetBuildingChildDto } from '../dtos/get.building.dto'; import { UpdateBuildingNameDto } from '../dtos/update.building.dto'; import { CheckCommunityTypeGuard } from 'src/guards/community.type.guard'; @@ -99,12 +95,10 @@ export class BuildingController { @ApiBearerAuth() @UseGuards(JwtAuthGuard) - @Get() - async getBuildingsByUserId( - @Query(ValidationPipe) dto: GetBuildingByUserIdDto, - ) { + @Get('user/:userUuid') + async getBuildingsByUserId(@Param('userUuid') userUuid: string) { try { - return await this.buildingService.getBuildingsByUserId(dto.userUuid); + return await this.buildingService.getBuildingsByUserId(userUuid); } catch (error) { throw new HttpException( error.message || 'Internal server error', diff --git a/src/building/dtos/get.building.dto.ts b/src/building/dtos/get.building.dto.ts index 720201a..f762469 100644 --- a/src/building/dtos/get.building.dto.ts +++ b/src/building/dtos/get.building.dto.ts @@ -49,13 +49,3 @@ export class GetBuildingChildDto { }) public includeSubSpaces: boolean = false; } - -export class GetBuildingByUserIdDto { - @ApiProperty({ - description: 'userUuid', - required: true, - }) - @IsString() - @IsNotEmpty() - public userUuid: string; -} diff --git a/src/community/controllers/community.controller.ts b/src/community/controllers/community.controller.ts index ea9805c..ab46154 100644 --- a/src/community/controllers/community.controller.ts +++ b/src/community/controllers/community.controller.ts @@ -10,15 +10,11 @@ import { Put, Query, UseGuards, - ValidationPipe, } from '@nestjs/common'; import { ApiTags, ApiBearerAuth } from '@nestjs/swagger'; import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard'; import { AddCommunityDto } from '../dtos/add.community.dto'; -import { - GetCommunitiesByUserIdDto, - GetCommunityChildDto, -} from '../dtos/get.community.dto'; +import { GetCommunityChildDto } from '../dtos/get.community.dto'; import { UpdateCommunityNameDto } from '../dtos/update.community.dto'; @ApiTags('Community Module') @@ -83,12 +79,10 @@ export class CommunityController { @ApiBearerAuth() @UseGuards(JwtAuthGuard) - @Get() - async getCommunitiesByUserId( - @Query(ValidationPipe) dto: GetCommunitiesByUserIdDto, - ) { + @Get('user/:userUuid') + async getCommunitiesByUserId(@Param('userUuid') userUuid: string) { try { - return await this.communityService.getCommunitiesByUserId(dto.userUuid); + return await this.communityService.getCommunitiesByUserId(userUuid); } catch (error) { throw new HttpException( error.message || 'Internal server error', diff --git a/src/community/dtos/get.community.dto.ts b/src/community/dtos/get.community.dto.ts index 5d0e08c..be614e5 100644 --- a/src/community/dtos/get.community.dto.ts +++ b/src/community/dtos/get.community.dto.ts @@ -49,13 +49,3 @@ export class GetCommunityChildDto { }) public includeSubSpaces: boolean = false; } - -export class GetCommunitiesByUserIdDto { - @ApiProperty({ - description: 'userUuid', - required: true, - }) - @IsString() - @IsNotEmpty() - public userUuid: string; -} diff --git a/src/floor/controllers/floor.controller.ts b/src/floor/controllers/floor.controller.ts index c1fa66f..fd22325 100644 --- a/src/floor/controllers/floor.controller.ts +++ b/src/floor/controllers/floor.controller.ts @@ -10,12 +10,11 @@ import { Put, Query, UseGuards, - ValidationPipe, } 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 { GetFloorByUserIdDto, GetFloorChildDto } from '../dtos/get.floor.dto'; +import { GetFloorChildDto } from '../dtos/get.floor.dto'; import { UpdateFloorNameDto } from '../dtos/update.floor.dto'; import { CheckBuildingTypeGuard } from 'src/guards/building.type.guard'; @@ -94,10 +93,10 @@ export class FloorController { @ApiBearerAuth() @UseGuards(JwtAuthGuard) - @Get() - async getFloorsByUserId(@Query(ValidationPipe) dto: GetFloorByUserIdDto) { + @Get('user/:userUuid') + async getFloorsByUserId(@Param('userUuid') userUuid: string) { try { - return await this.floorService.getFloorsByUserId(dto.userUuid); + return await this.floorService.getFloorsByUserId(userUuid); } catch (error) { throw new HttpException( error.message || 'Internal server error', diff --git a/src/floor/dtos/get.floor.dto.ts b/src/floor/dtos/get.floor.dto.ts index 40d0aed..23a8e56 100644 --- a/src/floor/dtos/get.floor.dto.ts +++ b/src/floor/dtos/get.floor.dto.ts @@ -49,13 +49,3 @@ export class GetFloorChildDto { }) public includeSubSpaces: boolean = false; } - -export class GetFloorByUserIdDto { - @ApiProperty({ - description: 'userUuid', - required: true, - }) - @IsString() - @IsNotEmpty() - public userUuid: string; -} diff --git a/src/room/controllers/room.controller.ts b/src/room/controllers/room.controller.ts index 80ef7cf..dee131f 100644 --- a/src/room/controllers/room.controller.ts +++ b/src/room/controllers/room.controller.ts @@ -8,16 +8,13 @@ import { Param, Post, Put, - Query, UseGuards, - ValidationPipe, } 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'; import { UpdateRoomNameDto } from '../dtos/update.room.dto'; import { CheckUnitTypeGuard } from 'src/guards/unit.type.guard'; -import { GetRoomByUserIdDto } from '../dtos/get.room.dto'; @ApiTags('Room Module') @Controller({ @@ -74,10 +71,10 @@ export class RoomController { @ApiBearerAuth() @UseGuards(JwtAuthGuard) - @Get() - async getRoomsByUserId(@Query(ValidationPipe) dto: GetRoomByUserIdDto) { + @Get('user/:userUuid') + async getRoomsByUserId(@Param('userUuid') userUuid: string) { try { - return await this.roomService.getRoomsByUserId(dto.userUuid); + return await this.roomService.getRoomsByUserId(userUuid); } catch (error) { throw new HttpException( error.message || 'Internal server error', diff --git a/src/room/dtos/get.room.dto.ts b/src/room/dtos/get.room.dto.ts deleted file mode 100644 index f919b85..0000000 --- a/src/room/dtos/get.room.dto.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ApiProperty } from '@nestjs/swagger'; -import { IsNotEmpty, IsString } from 'class-validator'; - -export class GetRoomByUserIdDto { - @ApiProperty({ - description: 'userUuid', - required: true, - }) - @IsString() - @IsNotEmpty() - public userUuid: string; -} diff --git a/src/unit/controllers/unit.controller.ts b/src/unit/controllers/unit.controller.ts index 245dd85..5289200 100644 --- a/src/unit/controllers/unit.controller.ts +++ b/src/unit/controllers/unit.controller.ts @@ -10,12 +10,11 @@ import { Put, Query, UseGuards, - ValidationPipe, } from '@nestjs/common'; import { ApiTags, ApiBearerAuth } from '@nestjs/swagger'; import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard'; import { AddUnitDto } from '../dtos/add.unit.dto'; -import { GetUnitByUserIdDto, GetUnitChildDto } from '../dtos/get.unit.dto'; +import { GetUnitChildDto } from '../dtos/get.unit.dto'; import { UpdateUnitNameDto } from '../dtos/update.unit.dto'; import { CheckFloorTypeGuard } from 'src/guards/floor.type.guard'; @@ -91,10 +90,10 @@ export class UnitController { @ApiBearerAuth() @UseGuards(JwtAuthGuard) - @Get() - async getUnitsByUserId(@Query(ValidationPipe) dto: GetUnitByUserIdDto) { + @Get('user/:userUuid') + async getUnitsByUserId(@Param('userUuid') userUuid: string) { try { - return await this.unitService.getUnitsByUserId(dto.userUuid); + return await this.unitService.getUnitsByUserId(userUuid); } catch (error) { throw new HttpException( error.message || 'Internal server error',