From 67331aa92a1c7fadd37e2558a0ca9585f67bd016 Mon Sep 17 00:00:00 2001 From: faris Aljohari <83524184+farisaljohari@users.noreply.github.com> Date: Wed, 14 May 2025 13:00:09 +0300 Subject: [PATCH] feat: update DEVICE_SPACE_COMMUNITY route and add validation for spaceUuid and communityUuid in DTO --- libs/common/src/constants/controller-route.ts | 4 +++- src/device/controllers/device-space-community.controller.ts | 2 +- src/device/dtos/get.device.dto.ts | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/common/src/constants/controller-route.ts b/libs/common/src/constants/controller-route.ts index 56c9bb4..7afbaa5 100644 --- a/libs/common/src/constants/controller-route.ts +++ b/libs/common/src/constants/controller-route.ts @@ -625,10 +625,12 @@ export class ControllerRoute { }; }; static DEVICE_SPACE_COMMUNITY = class { - public static readonly ROUTE = 'devices/recursive-child'; + public static readonly ROUTE = 'devices-space-community'; + static ACTIONS = class { public static readonly GET_ALL_DEVICES_BY_SPACE_OR_COMMUNITY_WITH_RECURSIVE_CHILD_SUMMARY = 'Get all devices by space or community with recursive child'; + public static readonly GET_ALL_DEVICES_BY_SPACE_OR_COMMUNITY_WITH_RECURSIVE_CHILD_DESCRIPTION = 'This endpoint retrieves all devices in the system by space or community with recursive child.'; }; diff --git a/src/device/controllers/device-space-community.controller.ts b/src/device/controllers/device-space-community.controller.ts index e19f1f5..bcad77e 100644 --- a/src/device/controllers/device-space-community.controller.ts +++ b/src/device/controllers/device-space-community.controller.ts @@ -23,7 +23,7 @@ export class DeviceSpaceOrCommunityController { @ApiBearerAuth() @UseGuards(PermissionsGuard) @Permissions('DEVICE_VIEW') - @Get() + @Get('recursive-child') @ApiOperation({ summary: ControllerRoute.DEVICE_SPACE_COMMUNITY.ACTIONS diff --git a/src/device/dtos/get.device.dto.ts b/src/device/dtos/get.device.dto.ts index 868b1e1..84c9d64 100644 --- a/src/device/dtos/get.device.dto.ts +++ b/src/device/dtos/get.device.dto.ts @@ -6,6 +6,7 @@ import { IsOptional, IsString, IsUUID, + ValidateIf, } from 'class-validator'; export class GetDeviceBySpaceUuidDto { @@ -66,4 +67,8 @@ export class GetDevicesBySpaceOrCommunityDto { @IsUUID('4', { message: 'Invalid community UUID format' }) @IsOptional() communityUuid?: string; + + @ValidateIf((o) => !o.spaceUuid && !o.communityUuid) + @IsNotEmpty({ message: 'Either spaceUuid or communityUuid must be provided' }) + requireEither?: never; // This ensures at least one of them is provided }