mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 20:44:53 +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 { 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({
|
||||||
|
|||||||
@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user