mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 09:54:55 +00:00
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 { 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 { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||||
import { GetDeviceDetailsInterface } from 'src/device/interfaces/get.device.interface';
|
import { GetDeviceDetailsInterface } from 'src/device/interfaces/get.device.interface';
|
||||||
import { GetSpaceParam } from '../dtos';
|
import { GetSpaceParam } from '../dtos';
|
||||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||||
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
||||||
import { ProductRepository } from '@app/common/modules/product/repositories';
|
|
||||||
import { SpaceService } from './space.service';
|
import { SpaceService } from './space.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SpaceDeviceService {
|
export class SpaceDeviceService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly spaceRepository: SpaceRepository,
|
|
||||||
private readonly tuyaService: TuyaService,
|
private readonly tuyaService: TuyaService,
|
||||||
private readonly productRepository: ProductRepository,
|
|
||||||
private readonly communityRepository: CommunityRepository,
|
|
||||||
private readonly spaceService: SpaceService,
|
private readonly spaceService: SpaceService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@ -29,6 +24,13 @@ export class SpaceDeviceService {
|
|||||||
projectUuid,
|
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) => {
|
const safeFetch = async (device: any) => {
|
||||||
try {
|
try {
|
||||||
const tuyaDetails = await this.getDeviceDetailsByDeviceIdTuya(
|
const tuyaDetails = await this.getDeviceDetailsByDeviceIdTuya(
|
||||||
|
|||||||
@ -325,6 +325,7 @@ export class SpaceService {
|
|||||||
private async validateSpace(spaceUuid: string) {
|
private async validateSpace(spaceUuid: string) {
|
||||||
const space = await this.spaceRepository.findOne({
|
const space = await this.spaceRepository.findOne({
|
||||||
where: { uuid: spaceUuid },
|
where: { uuid: spaceUuid },
|
||||||
|
relations: ['devices'],
|
||||||
});
|
});
|
||||||
if (!space) this.throwNotFound('Space', spaceUuid);
|
if (!space) this.throwNotFound('Space', spaceUuid);
|
||||||
return space;
|
return space;
|
||||||
|
|||||||
Reference in New Issue
Block a user