Refactor controllers to use userUuid as route param

This commit is contained in:
faris Aljohari
2024-04-16 16:11:43 +03:00
parent f30dd755a2
commit 74b7471106
9 changed files with 19 additions and 78 deletions
@@ -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',
-10
View File
@@ -49,13 +49,3 @@ export class GetBuildingChildDto {
})
public includeSubSpaces: boolean = false;
}
export class GetBuildingByUserIdDto {
@ApiProperty({
description: 'userUuid',
required: true,
})
@IsString()
@IsNotEmpty()
public userUuid: string;
}
@@ -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',
-10
View File
@@ -49,13 +49,3 @@ export class GetCommunityChildDto {
})
public includeSubSpaces: boolean = false;
}
export class GetCommunitiesByUserIdDto {
@ApiProperty({
description: 'userUuid',
required: true,
})
@IsString()
@IsNotEmpty()
public userUuid: string;
}
+4 -5
View File
@@ -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',
-10
View File
@@ -49,13 +49,3 @@ export class GetFloorChildDto {
})
public includeSubSpaces: boolean = false;
}
export class GetFloorByUserIdDto {
@ApiProperty({
description: 'userUuid',
required: true,
})
@IsString()
@IsNotEmpty()
public userUuid: string;
}
+3 -6
View File
@@ -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',
-12
View File
@@ -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;
}
+4 -5
View File
@@ -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',