mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 18:34:54 +00:00
Refactor unit service to remove unnecessary includeSubSpaces parameter
This commit is contained in:
@ -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({
|
||||
|
||||
@ -79,7 +79,7 @@ export class UnitService {
|
||||
getUnitChildDto: GetUnitChildDto,
|
||||
): Promise<UnitChildInterface> {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user