mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-08-25 16:19:38 +00:00
108 lines
2.4 KiB
TypeScript
108 lines
2.4 KiB
TypeScript
import { DeviceTypeEnum } from '@app/common/constants/device-type.enum';
|
|
import { ApiProperty } from '@nestjs/swagger';
|
|
import { Transform } from 'class-transformer';
|
|
import {
|
|
IsEnum,
|
|
IsNotEmpty,
|
|
IsOptional,
|
|
IsString,
|
|
IsUUID,
|
|
ValidateIf,
|
|
} from 'class-validator';
|
|
|
|
export class GetDeviceBySpaceUuidDto {
|
|
@ApiProperty({
|
|
description: 'spaceUuid',
|
|
required: true,
|
|
})
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
public spaceUuid: string;
|
|
}
|
|
export class GetDeviceLogsDto {
|
|
@ApiProperty({
|
|
description: 'code',
|
|
required: true,
|
|
})
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
public code: string;
|
|
@ApiProperty({
|
|
description: 'startTime',
|
|
required: false,
|
|
})
|
|
@IsString()
|
|
@IsOptional()
|
|
public startTime: string;
|
|
@ApiProperty({
|
|
description: 'endTime',
|
|
required: false,
|
|
})
|
|
@IsString()
|
|
@IsOptional()
|
|
public endTime: string;
|
|
}
|
|
|
|
export class GetDevicesBySpaceOrCommunityDto {
|
|
@ApiProperty({
|
|
description: 'Device Product Type',
|
|
example: 'PC',
|
|
required: true,
|
|
})
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
public productType: string;
|
|
@IsUUID('4', { message: 'Invalid space UUID format' })
|
|
@IsOptional()
|
|
spaceUuid?: string;
|
|
|
|
@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
|
|
}
|
|
|
|
export class GetDevicesFilterDto {
|
|
@ApiProperty({
|
|
description: 'Device Type',
|
|
enum: DeviceTypeEnum,
|
|
required: false,
|
|
})
|
|
@IsEnum(DeviceTypeEnum)
|
|
@IsOptional()
|
|
public deviceType: DeviceTypeEnum;
|
|
|
|
@ApiProperty({
|
|
description: 'List of Space IDs to filter devices',
|
|
required: false,
|
|
example: ['60d21b4667d0d8992e610c85', '60d21b4967d0d8992e610c86'],
|
|
})
|
|
@IsOptional()
|
|
@Transform(({ value }) => {
|
|
if (!Array.isArray(value)) {
|
|
return [value];
|
|
}
|
|
return value;
|
|
})
|
|
@IsUUID('4', { each: true })
|
|
public spaces?: string[];
|
|
|
|
@ApiProperty({
|
|
description: 'List of Community IDs to filter devices',
|
|
required: false,
|
|
example: ['60d21b4667d0d8992e610c85', '60d21b4967d0d8992e610c86'],
|
|
})
|
|
@Transform(({ value }) => {
|
|
if (!Array.isArray(value)) {
|
|
return [value];
|
|
}
|
|
return value;
|
|
})
|
|
@IsOptional()
|
|
@IsUUID('4', { each: true })
|
|
public communities?: string[];
|
|
}
|