Refactor unit service to remove unnecessary includeSubSpaces parameter

This commit is contained in:
faris Aljohari
2024-04-28 11:39:49 +03:00
parent c376e69e67
commit cd2f496670
2 changed files with 3 additions and 29 deletions

View File

@ -1,13 +1,5 @@
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer'; import { IsInt, IsNotEmpty, IsString, Min } from 'class-validator';
import {
IsBoolean,
IsInt,
IsNotEmpty,
IsOptional,
IsString,
Min,
} from 'class-validator';
export class GetUnitDto { export class GetUnitDto {
@ApiProperty({ @ApiProperty({
@ -35,19 +27,6 @@ export class GetUnitChildDto {
@Min(1, { message: 'Page size must not be less than 1' }) @Min(1, { message: 'Page size must not be less than 1' })
@IsNotEmpty() @IsNotEmpty()
public pageSize: number; 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 { export class GetUnitByUserIdDto {
@ApiProperty({ @ApiProperty({

View File

@ -79,7 +79,7 @@ export class UnitService {
getUnitChildDto: GetUnitChildDto, getUnitChildDto: GetUnitChildDto,
): Promise<UnitChildInterface> { ): Promise<UnitChildInterface> {
try { try {
const { includeSubSpaces, page, pageSize } = getUnitChildDto; const { page, pageSize } = getUnitChildDto;
const space = await this.spaceRepository.findOneOrFail({ const space = await this.spaceRepository.findOneOrFail({
where: { uuid: unitUuid }, where: { uuid: unitUuid },
@ -94,12 +94,7 @@ export class UnitService {
where: { parent: { uuid: space.uuid } }, where: { parent: { uuid: space.uuid } },
}); });
const children = await this.buildHierarchy( const children = await this.buildHierarchy(space, false, page, pageSize);
space,
includeSubSpaces,
page,
pageSize,
);
return { return {
uuid: space.uuid, uuid: space.uuid,