mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-24 11:17:54 +00:00
feat: update device and space services to use productType instead of deviceType and add query support for device retrieval by product type
This commit is contained in:
@@ -58,7 +58,7 @@ export class GetDevicesBySpaceOrCommunityDto {
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public deviceType: string;
|
||||
public productType: string;
|
||||
@IsUUID('4', { message: 'Invalid space UUID format' })
|
||||
@IsOptional()
|
||||
spaceUuid?: string;
|
||||
|
||||
@@ -1729,7 +1729,7 @@ export class DeviceService {
|
||||
query: GetDevicesBySpaceOrCommunityDto,
|
||||
): Promise<BaseResponseDto> {
|
||||
try {
|
||||
const { spaceUuid, communityUuid, deviceType } = query;
|
||||
const { spaceUuid, communityUuid, productType } = query;
|
||||
if (!spaceUuid && !communityUuid) {
|
||||
throw new BadRequestException(
|
||||
'Either spaceUuid or communityUuid must be provided',
|
||||
@@ -1750,12 +1750,12 @@ export class DeviceService {
|
||||
}
|
||||
|
||||
const devicesFilterd = devices.filter(
|
||||
(device) => device.productDevice?.prodType === deviceType,
|
||||
(device) => device.productDevice?.prodType === productType,
|
||||
);
|
||||
|
||||
if (devicesFilterd.length === 0) {
|
||||
return new SuccessResponseDto({
|
||||
message: `No ${deviceType} devices found for ${spaceUuid ? 'space' : 'community'}`,
|
||||
message: `No ${productType} devices found for ${spaceUuid ? 'space' : 'community'}`,
|
||||
data: [],
|
||||
statusCode: HttpStatus.CREATED,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user