diff --git a/src/automation/controllers/automation.controller.ts b/src/automation/controllers/automation.controller.ts index e608d96..675cd0b 100644 --- a/src/automation/controllers/automation.controller.ts +++ b/src/automation/controllers/automation.controller.ts @@ -48,8 +48,8 @@ export class AutomationController { @ApiBearerAuth() @UseGuards(JwtAuthGuard) @Get(':spaceUuid') - async getAutomationByUnit(@Param() param: SpaceParamDto) { - const automation = await this.automationService.getAutomationByUnit( + async getAutomationBySpace(@Param() param: SpaceParamDto) { + const automation = await this.automationService.getAutomationBySpace( param.spaceUuid, ); return automation; diff --git a/src/automation/interface/automation.interface.ts b/src/automation/interface/automation.interface.ts index 298d58c..eed3ef7 100644 --- a/src/automation/interface/automation.interface.ts +++ b/src/automation/interface/automation.interface.ts @@ -5,7 +5,7 @@ export interface AddAutomationInterface { id: string; }; } -export interface GetAutomationByUnitInterface { +export interface GetAutomationBySpaceInterface { success: boolean; msg?: string; result: { diff --git a/src/automation/services/automation.service.ts b/src/automation/services/automation.service.ts index f0c236b..793fa9f 100644 --- a/src/automation/services/automation.service.ts +++ b/src/automation/services/automation.service.ts @@ -20,7 +20,7 @@ import { AutomationDetailsResult, AutomationResponseData, DeleteAutomationInterface, - GetAutomationByUnitInterface, + GetAutomationBySpaceInterface, } from '../interface/automation.interface'; import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter'; import { @@ -48,20 +48,18 @@ export class AutomationService { async addAutomation(addAutomationDto: AddAutomationDto, spaceTuyaId = null) { try { - let unitSpaceTuyaId; + let tuyaSpaceId; if (!spaceTuyaId) { - const unitDetails = await this.getUnitByUuid( - addAutomationDto.spaceUuid, - ); + const space = await this.getSpaceByUuid(addAutomationDto.spaceUuid); - unitSpaceTuyaId = unitDetails.spaceTuyaUuid; - if (!unitDetails) { + tuyaSpaceId = space.spaceTuyaUuid; + if (!space) { throw new BadRequestException( `Invalid space UUID ${addAutomationDto.spaceUuid}`, ); } } else { - unitSpaceTuyaId = spaceTuyaId; + tuyaSpaceId = spaceTuyaId; } const actions = addAutomationDto.actions.map((action) => @@ -100,7 +98,7 @@ export class AutomationService { method: 'POST', path, body: { - space_id: unitSpaceTuyaId, + space_id: tuyaSpaceId, name: addAutomationDto.automationName, effective_time: { ...addAutomationDto.effectiveTime, @@ -129,7 +127,7 @@ export class AutomationService { } } } - async getUnitByUuid(spaceUuid: string) { + async getSpaceByUuid(spaceUuid: string) { try { const space = await this.spaceRepository.findOne({ where: { @@ -151,19 +149,19 @@ export class AutomationService { if (err instanceof BadRequestException) { throw err; // Re-throw BadRequestException } else { - throw new HttpException('Unit not found', HttpStatus.NOT_FOUND); + throw new HttpException('Space not found', HttpStatus.NOT_FOUND); } } } - async getAutomationByUnit(spaceUuid: string) { + async getAutomationBySpace(spaceUuid: string) { try { - const unit = await this.getUnitByUuid(spaceUuid); - if (!unit.spaceTuyaUuid) { + const space = await this.getSpaceByUuid(spaceUuid); + if (!space.spaceTuyaUuid) { throw new BadRequestException(`Invalid space UUID ${spaceUuid}`); } - const path = `/v2.0/cloud/scene/rule?space_id=${unit.spaceTuyaUuid}&type=automation`; - const response: GetAutomationByUnitInterface = await this.tuya.request({ + const path = `/v2.0/cloud/scene/rule?space_id=${space.spaceTuyaUuid}&type=automation`; + const response: GetAutomationBySpaceInterface = await this.tuya.request({ method: 'GET', path, }); @@ -314,18 +312,18 @@ export class AutomationService { async deleteAutomation(param: DeleteAutomationParamDto, spaceTuyaId = null) { try { const { automationUuid, spaceUuid } = param; - let unitSpaceTuyaId; + let tuyaSpaceId; if (!spaceTuyaId) { - const space = await this.getUnitByUuid(spaceUuid); - unitSpaceTuyaId = space.spaceTuyaUuid; - if (!unitSpaceTuyaId) { + const space = await this.getSpaceByUuid(spaceUuid); + tuyaSpaceId = space.spaceTuyaUuid; + if (!tuyaSpaceId) { throw new BadRequestException(`Invalid space UUID ${spaceUuid}`); } } else { - unitSpaceTuyaId = spaceTuyaId; + tuyaSpaceId = spaceTuyaId; } - const path = `/v2.0/cloud/scene/rule?ids=${automationUuid}&space_id=${unitSpaceTuyaId}`; + const path = `/v2.0/cloud/scene/rule?ids=${automationUuid}&space_id=${tuyaSpaceId}`; const response: DeleteAutomationInterface = await this.tuya.request({ method: 'DELETE', path, @@ -392,7 +390,7 @@ export class AutomationService { automationUuid: string, ) { try { - const space = await this.getUnitByUuid( + const space = await this.getSpaceByUuid( updateAutomationStatusDto.spaceUuid, ); if (!space.spaceTuyaUuid) {