From f1c07360cb443703a98bfe5cc2d5456393dc3d6f Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Wed, 30 Oct 2024 23:50:52 +0400 Subject: [PATCH] updated spaceUuid --- .../modules/scene/entities/scene.entity.ts | 3 ++- src/automation/services/automation.service.ts | 4 ++-- src/scene/controllers/scene.controller.ts | 9 ++++---- src/scene/services/scene.service.ts | 22 ++++++++++++------- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/libs/common/src/modules/scene/entities/scene.entity.ts b/libs/common/src/modules/scene/entities/scene.entity.ts index 2ade9ad..1e04fd7 100644 --- a/libs/common/src/modules/scene/entities/scene.entity.ts +++ b/libs/common/src/modules/scene/entities/scene.entity.ts @@ -47,7 +47,8 @@ export class SceneEntity extends AbstractEntity { @Column({ nullable: false, }) - unitUuid: string; + spaceUuid: string; + @Column({ nullable: false, }) diff --git a/src/automation/services/automation.service.ts b/src/automation/services/automation.service.ts index f25f7c1..f0c236b 100644 --- a/src/automation/services/automation.service.ts +++ b/src/automation/services/automation.service.ts @@ -192,10 +192,10 @@ export class AutomationService { } } async getTapToRunSceneDetailsTuya( - sceneId: string, + sceneUuid: string, ): Promise { try { - const path = `/v2.0/cloud/scene/rule/${sceneId}`; + const path = `/v2.0/cloud/scene/rule/${sceneUuid}`; const response = await this.tuya.request({ method: 'GET', path, diff --git a/src/scene/controllers/scene.controller.ts b/src/scene/controllers/scene.controller.ts index ecdbe6d..27ae0c7 100644 --- a/src/scene/controllers/scene.controller.ts +++ b/src/scene/controllers/scene.controller.ts @@ -60,7 +60,7 @@ export class SceneController { @ApiBearerAuth() @UseGuards(JwtAuthGuard) - @Delete('tap-to-run/:unitUuid/:sceneId') + @Delete('tap-to-run/:unitUuid/:sceneUuid') async deleteTapToRunScene(@Param() param: DeleteSceneParamDto) { await this.sceneService.deleteTapToRunScene(param); return { @@ -70,7 +70,7 @@ export class SceneController { } @ApiBearerAuth() @UseGuards(JwtAuthGuard) - @Post('tap-to-run/trigger/:sceneId') + @Post('tap-to-run/trigger/:sceneUuid') async triggerTapToRunScene(@Param() param: SceneParamDto) { await this.sceneService.triggerTapToRunScene(param.sceneUuid); return { @@ -82,7 +82,7 @@ export class SceneController { @ApiBearerAuth() @UseGuards(JwtAuthGuard) - @Get('tap-to-run/details/:sceneId') + @Get('tap-to-run/details/:sceneUuid') async getTapToRunSceneDetails(@Param() param: SceneParamDto) { const tapToRunScenes = await this.sceneService.getTapToRunSceneDetails( param.sceneUuid, @@ -92,7 +92,7 @@ export class SceneController { @ApiBearerAuth() @UseGuards(JwtAuthGuard) - @Put('tap-to-run/:sceneId') + @Put('tap-to-run/:sceneUuid') async updateTapToRunScene( @Body() updateSceneTapToRunDto: UpdateSceneTapToRunDto, @Param() param: SceneParamDto, @@ -108,6 +108,7 @@ export class SceneController { data: tapToRunScene, }; } + @ApiBearerAuth() @UseGuards(JwtAuthGuard) @Post('icon') diff --git a/src/scene/services/scene.service.ts b/src/scene/services/scene.service.ts index 566b526..61e6af4 100644 --- a/src/scene/services/scene.service.ts +++ b/src/scene/services/scene.service.ts @@ -113,7 +113,7 @@ export class SceneService { : defaultSceneIcon.uuid, }, showInHomePage: addSceneTapToRunDto.showInHomePage, - unitUuid: spaceUuid ? spaceUuid : addSceneTapToRunDto.spaceUuid, + spaceUuid: spaceUuid ? spaceUuid : addSceneTapToRunDto.spaceUuid, }); } return { @@ -124,7 +124,7 @@ export class SceneService { throw err; // Re-throw BadRequestException } else { throw new HttpException( - err.message || 'Scene not found', + err.message || `Scene not found`, err.status || HttpStatus.NOT_FOUND, ); } @@ -160,13 +160,14 @@ export class SceneService { } } } - async getTapToRunSceneByUnit(unitUuid: string, inHomePage: GetSceneDto) { + + async getTapToRunSceneByUnit(spaceUuid: string, inHomePage: GetSceneDto) { try { const showInHomePage = inHomePage?.showInHomePage; const scenesData = await this.sceneRepository.find({ where: { - unitUuid, + spaceUuid, ...(showInHomePage ? { showInHomePage } : {}), }, }); @@ -180,6 +181,7 @@ export class SceneService { // eslint-disable-next-line @typescript-eslint/no-unused-vars const { actions, ...rest } = sceneData; return { + uuid: scene.uuid, ...rest, }; }), @@ -197,6 +199,7 @@ export class SceneService { } } } + async deleteTapToRunScene(param: DeleteSceneParamDto, spaceTuyaId = null) { const { spaceUuid, sceneUuid } = param; try { @@ -317,7 +320,10 @@ export class SceneService { if (err instanceof BadRequestException) { throw err; // Re-throw BadRequestException } else { - throw new HttpException('Scene not found', HttpStatus.NOT_FOUND); + throw new HttpException( + `Scene not found for ${sceneId}`, + HttpStatus.NOT_FOUND, + ); } } } @@ -375,7 +381,7 @@ export class SceneService { const newTapToRunScene = await this.addTapToRunScene( addSceneTapToRunDto, spaceTuyaId.spaceId, - scene.unitUuid, + scene.spaceUuid, ); const param: DeleteSceneParamDto = { @@ -394,7 +400,7 @@ export class SceneService { sceneIcon: { uuid: addSceneTapToRunDto.iconUuid, }, - unitUuid: scene.unitUuid, + spaceUuid: scene.spaceUuid, }, ); return newTapToRunScene; @@ -404,7 +410,7 @@ export class SceneService { throw err; // Re-throw BadRequestException } else { throw new HttpException( - err.message || 'Scene not found', + err.message || `Scene not found for id ${sceneUuid}`, err.status || HttpStatus.NOT_FOUND, ); }