mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 02:36:19 +00:00
Merge pull request #176 from SyncrowIOT/bugfix/fix-get-devices-in-space
fixed issue in getting device details from space
This commit is contained in:
@ -1,22 +1,17 @@
|
||||
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
||||
import { CommunityRepository } from '@app/common/modules/community/repositories';
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { GetDeviceDetailsInterface } from 'src/device/interfaces/get.device.interface';
|
||||
import { GetSpaceParam } from '../dtos';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
||||
import { ProductRepository } from '@app/common/modules/product/repositories';
|
||||
import { SpaceService } from './space.service';
|
||||
|
||||
@Injectable()
|
||||
export class SpaceDeviceService {
|
||||
constructor(
|
||||
private readonly spaceRepository: SpaceRepository,
|
||||
private readonly tuyaService: TuyaService,
|
||||
private readonly productRepository: ProductRepository,
|
||||
private readonly communityRepository: CommunityRepository,
|
||||
private readonly spaceService: SpaceService,
|
||||
) {}
|
||||
|
||||
@ -29,6 +24,12 @@ export class SpaceDeviceService {
|
||||
projectUuid,
|
||||
);
|
||||
|
||||
if (!Array.isArray(space.devices)) {
|
||||
throw new HttpException(
|
||||
'The space does not contain any devices or the devices property is invalid.',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
const safeFetch = async (device: any) => {
|
||||
try {
|
||||
const tuyaDetails = await this.getDeviceDetailsByDeviceIdTuya(
|
||||
@ -46,7 +47,7 @@ export class SpaceDeviceService {
|
||||
};
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Skipping device with deviceTuyaUuid: ${device.deviceTuyaUuid} due to error.`,
|
||||
`Skipping device with deviceTuyaUuid: ${device.deviceTuyaUuid} due to error. ${error}`,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
@ -325,6 +325,7 @@ export class SpaceService {
|
||||
private async validateSpace(spaceUuid: string) {
|
||||
const space = await this.spaceRepository.findOne({
|
||||
where: { uuid: spaceUuid },
|
||||
relations: ['devices', 'devices.productDevice'],
|
||||
});
|
||||
if (!space) this.throwNotFound('Space', spaceUuid);
|
||||
return space;
|
||||
|
Reference in New Issue
Block a user