From b3f8b928262381aa470f483fb77def98f596571d Mon Sep 17 00:00:00 2001 From: ZaydSkaff Date: Mon, 30 Jun 2025 15:35:23 +0300 Subject: [PATCH] ensure Timer is the category value for CUR2 type (#446) --- src/schedule/services/schedule.service.ts | 39 +++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/schedule/services/schedule.service.ts b/src/schedule/services/schedule.service.ts index d88ee20..e89c6d8 100644 --- a/src/schedule/services/schedule.service.ts +++ b/src/schedule/services/schedule.service.ts @@ -96,6 +96,16 @@ export class ScheduleService { throw new HttpException('Device Not Found', HttpStatus.NOT_FOUND); } + if ( + deviceDetails.productDevice.prodType == ProductType.CUR_2 && + addScheduleDto.category != 'Timer' + ) { + throw new HttpException( + 'Invalid category for CUR_2 devices', + HttpStatus.BAD_REQUEST, + ); + } + this.ensureProductTypeSupportedForSchedule( deviceDetails.productDevice.prodType as ProductType, ); @@ -103,6 +113,7 @@ export class ScheduleService { await this.addScheduleDeviceInTuya( deviceDetails.deviceTuyaUuid, addScheduleDto, + deviceDetails.productDevice.prodType as ProductType, ); } catch (error) { throw new HttpException( @@ -128,7 +139,10 @@ export class ScheduleService { ); const result = schedules.result.map((schedule: any) => { return { - category: schedule.category.replace('category_', ''), + category: + deviceDetails.productDevice.prodType == ProductType.CUR_2 + ? schedule.category + : schedule.category.replace('category_', ''), enable: schedule.enable, function: { code: schedule.functions[0].code, @@ -159,6 +173,16 @@ export class ScheduleService { throw new HttpException('Device Not Found', HttpStatus.NOT_FOUND); } + if ( + deviceDetails.productDevice.prodType == ProductType.CUR_2 && + updateScheduleDto.category != 'Timer' + ) { + throw new HttpException( + 'Invalid category for CUR_2 devices', + HttpStatus.BAD_REQUEST, + ); + } + // Corrected condition for supported device types this.ensureProductTypeSupportedForSchedule( deviceDetails.productDevice.prodType as ProductType, @@ -167,6 +191,7 @@ export class ScheduleService { await this.updateScheduleDeviceInTuya( deviceDetails.deviceTuyaUuid, updateScheduleDto, + deviceDetails.productDevice.prodType as ProductType, ); } catch (error) { throw new HttpException( @@ -192,6 +217,7 @@ export class ScheduleService { private async addScheduleDeviceInTuya( deviceId: string, addScheduleDto: AddScheduleDto, + deviceType: ProductType, ): Promise { try { const convertedTime = convertTimestampToDubaiTime(addScheduleDto.time); @@ -210,7 +236,10 @@ export class ScheduleService { ...addScheduleDto.function, }, ], - category: `category_${addScheduleDto.category}`, + category: + deviceType == ProductType.CUR_2 + ? addScheduleDto.category + : `category_${addScheduleDto.category}`, }, }); @@ -248,6 +277,7 @@ export class ScheduleService { private async updateScheduleDeviceInTuya( deviceId: string, updateScheduleDto: UpdateScheduleDto, + deviceType: ProductType, ): Promise { try { const convertedTime = convertTimestampToDubaiTime(updateScheduleDto.time); @@ -268,7 +298,10 @@ export class ScheduleService { value: updateScheduleDto.function.value, }, ], - category: `category_${updateScheduleDto.category}`, + category: + deviceType == ProductType.CUR_2 + ? updateScheduleDto.category + : `category_${updateScheduleDto.category}`, }, });