finished 4scene configration endpoints

This commit is contained in:
faris Aljohari
2024-11-16 23:05:06 -06:00
parent 4bb598d8b0
commit eb916b79b4
25 changed files with 429 additions and 15 deletions
+2
View File
@@ -13,6 +13,7 @@ import {
SceneRepository,
} from '@app/common/modules/scene/repositories';
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
import { SceneDeviceRepository } from '@app/common/modules/scene-device/repositories';
@Module({
imports: [ConfigModule, SpaceRepositoryModule, DeviceStatusFirebaseModule],
@@ -26,6 +27,7 @@ import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service
ProductRepository,
SceneIconRepository,
SceneRepository,
SceneDeviceRepository,
],
exports: [SceneService],
})
+9 -8
View File
@@ -3,6 +3,8 @@ import {
HttpException,
HttpStatus,
BadRequestException,
forwardRef,
Inject,
} from '@nestjs/common';
import { SpaceRepository } from '@app/common/modules/space/repositories';
import {
@@ -14,7 +16,6 @@ import {
UpdateSceneTapToRunDto,
} from '../dtos';
import { convertKeysToSnakeCase } from '@app/common/helper/snakeCaseConverter';
import { DeviceService } from 'src/device/services';
import {
AddTapToRunSceneInterface,
DeleteTapToRunSceneInterface,
@@ -37,6 +38,7 @@ import { BaseResponseDto } from '@app/common/dto/base.response.dto';
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
import { HttpStatusCode } from 'axios';
import { ConvertedAction } from '@app/common/integrations/tuya/interfaces';
import { DeviceService } from 'src/device/services';
@Injectable()
export class SceneService {
@@ -44,8 +46,9 @@ export class SceneService {
private readonly spaceRepository: SpaceRepository,
private readonly sceneIconRepository: SceneIconRepository,
private readonly sceneRepository: SceneRepository,
private readonly deviceService: DeviceService,
private readonly tuyaService: TuyaService,
@Inject(forwardRef(() => DeviceService))
private readonly deviceService: DeviceService,
) {}
async createScene(
@@ -178,7 +181,10 @@ export class SceneService {
});
if (!scenesData.length) {
return [];
throw new HttpException(
`No scenes found for space UUID ${spaceUuid} with showInHomePage ${showInHomePage} `,
HttpStatus.NOT_FOUND,
);
}
const scenes = await Promise.all(
@@ -438,7 +444,6 @@ export class SceneService {
if (err instanceof BadRequestException) {
throw err;
} else {
console.log(err);
throw new HttpException(
`An error occurred while retrieving scene details for ${scene.uuid}`,
HttpStatus.INTERNAL_SERVER_ERROR,
@@ -454,9 +459,6 @@ export class SceneService {
const space = await this.getSpaceByUuid(scene.spaceUuid);
await this.delete(scene.sceneTuyaUuid, space.spaceTuyaUuid);
await this.sceneRepository.remove(scene);
return new SuccessResponseDto({
message: `Scene with ID ${sceneUuid} deleted successfully`,
});
@@ -564,7 +566,6 @@ export class SceneService {
};
} catch (err) {
if (err instanceof BadRequestException) {
console.log(err);
throw err;
} else {
throw new HttpException(