Merge pull request #372 from SyncrowIOT/fix-get-devices-by-product-type

feat: update DEVICE_SPACE_COMMUNITY route and add validation for spaceUuid and communityUuid in DTO
This commit is contained in:
faljawhary
2025-05-14 13:00:46 +03:00
committed by GitHub
3 changed files with 9 additions and 2 deletions

View File

@ -625,10 +625,12 @@ export class ControllerRoute {
}; };
}; };
static DEVICE_SPACE_COMMUNITY = class { static DEVICE_SPACE_COMMUNITY = class {
public static readonly ROUTE = 'devices/recursive-child'; public static readonly ROUTE = 'devices-space-community';
static ACTIONS = class { static ACTIONS = class {
public static readonly GET_ALL_DEVICES_BY_SPACE_OR_COMMUNITY_WITH_RECURSIVE_CHILD_SUMMARY = public static readonly GET_ALL_DEVICES_BY_SPACE_OR_COMMUNITY_WITH_RECURSIVE_CHILD_SUMMARY =
'Get all devices by space or community with recursive child'; 'Get all devices by space or community with recursive child';
public static readonly GET_ALL_DEVICES_BY_SPACE_OR_COMMUNITY_WITH_RECURSIVE_CHILD_DESCRIPTION = 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.'; 'This endpoint retrieves all devices in the system by space or community with recursive child.';
}; };

View File

@ -23,7 +23,7 @@ export class DeviceSpaceOrCommunityController {
@ApiBearerAuth() @ApiBearerAuth()
@UseGuards(PermissionsGuard) @UseGuards(PermissionsGuard)
@Permissions('DEVICE_VIEW') @Permissions('DEVICE_VIEW')
@Get() @Get('recursive-child')
@ApiOperation({ @ApiOperation({
summary: summary:
ControllerRoute.DEVICE_SPACE_COMMUNITY.ACTIONS ControllerRoute.DEVICE_SPACE_COMMUNITY.ACTIONS

View File

@ -6,6 +6,7 @@ import {
IsOptional, IsOptional,
IsString, IsString,
IsUUID, IsUUID,
ValidateIf,
} from 'class-validator'; } from 'class-validator';
export class GetDeviceBySpaceUuidDto { export class GetDeviceBySpaceUuidDto {
@ -66,4 +67,8 @@ export class GetDevicesBySpaceOrCommunityDto {
@IsUUID('4', { message: 'Invalid community UUID format' }) @IsUUID('4', { message: 'Invalid community UUID format' })
@IsOptional() @IsOptional()
communityUuid?: string; 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
} }