From cd2f4966701d323ea9b122796077cfa86ca52ff8 Mon Sep 17 00:00:00 2001 From: faris Aljohari <83524184+farisaljohari@users.noreply.github.com> Date: Sun, 28 Apr 2024 11:39:49 +0300 Subject: [PATCH] Refactor unit service to remove unnecessary includeSubSpaces parameter --- src/unit/dtos/get.unit.dto.ts | 23 +---------------------- src/unit/services/unit.service.ts | 9 ++------- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/src/unit/dtos/get.unit.dto.ts b/src/unit/dtos/get.unit.dto.ts index 82837aa..2fae52a 100644 --- a/src/unit/dtos/get.unit.dto.ts +++ b/src/unit/dtos/get.unit.dto.ts @@ -1,13 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { Transform } from 'class-transformer'; -import { - IsBoolean, - IsInt, - IsNotEmpty, - IsOptional, - IsString, - Min, -} from 'class-validator'; +import { IsInt, IsNotEmpty, IsString, Min } from 'class-validator'; export class GetUnitDto { @ApiProperty({ @@ -35,19 +27,6 @@ export class GetUnitChildDto { @Min(1, { message: 'Page size must not be less than 1' }) @IsNotEmpty() public pageSize: number; - - @ApiProperty({ - example: true, - description: 'Flag to determine whether to fetch full hierarchy', - required: false, - default: false, - }) - @IsOptional() - @IsBoolean() - @Transform((value) => { - return value.obj.includeSubSpaces === 'true'; - }) - public includeSubSpaces: boolean = false; } export class GetUnitByUserIdDto { @ApiProperty({ diff --git a/src/unit/services/unit.service.ts b/src/unit/services/unit.service.ts index 867300c..1daa297 100644 --- a/src/unit/services/unit.service.ts +++ b/src/unit/services/unit.service.ts @@ -79,7 +79,7 @@ export class UnitService { getUnitChildDto: GetUnitChildDto, ): Promise { try { - const { includeSubSpaces, page, pageSize } = getUnitChildDto; + const { page, pageSize } = getUnitChildDto; const space = await this.spaceRepository.findOneOrFail({ where: { uuid: unitUuid }, @@ -94,12 +94,7 @@ export class UnitService { where: { parent: { uuid: space.uuid } }, }); - const children = await this.buildHierarchy( - space, - includeSubSpaces, - page, - pageSize, - ); + const children = await this.buildHierarchy(space, false, page, pageSize); return { uuid: space.uuid,