mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 07:07:21 +00:00
add cur2 checks to schedule
This commit is contained in:
@ -162,6 +162,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,
|
||||
);
|
||||
}
|
||||
|
||||
// Corrected condition for supported device types
|
||||
if (
|
||||
deviceDetails.productDevice.prodType !== ProductType.THREE_G &&
|
||||
@ -182,6 +192,7 @@ export class ScheduleService {
|
||||
await this.addScheduleDeviceInTuya(
|
||||
deviceDetails.deviceTuyaUuid,
|
||||
addScheduleDto,
|
||||
deviceDetails.productDevice.prodType as ProductType,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
@ -193,6 +204,7 @@ export class ScheduleService {
|
||||
async addScheduleDeviceInTuya(
|
||||
deviceId: string,
|
||||
addScheduleDto: AddScheduleDto,
|
||||
deviceType: ProductType,
|
||||
): Promise<addScheduleDeviceInterface> {
|
||||
try {
|
||||
const convertedTime = convertTimestampToDubaiTime(addScheduleDto.time);
|
||||
@ -212,7 +224,10 @@ export class ScheduleService {
|
||||
value: addScheduleDto.function.value,
|
||||
},
|
||||
],
|
||||
category: `category_${addScheduleDto.category}`,
|
||||
category:
|
||||
deviceType == ProductType.CUR_2
|
||||
? addScheduleDto.category
|
||||
: `category_${addScheduleDto.category}`,
|
||||
},
|
||||
});
|
||||
|
||||
@ -254,7 +269,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,
|
||||
@ -318,6 +336,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
|
||||
if (
|
||||
deviceDetails.productDevice.prodType !== ProductType.THREE_G &&
|
||||
@ -338,6 +366,7 @@ export class ScheduleService {
|
||||
await this.updateScheduleDeviceInTuya(
|
||||
deviceDetails.deviceTuyaUuid,
|
||||
updateScheduleDto,
|
||||
deviceDetails.productDevice.prodType as ProductType,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
@ -349,6 +378,7 @@ export class ScheduleService {
|
||||
async updateScheduleDeviceInTuya(
|
||||
deviceId: string,
|
||||
updateScheduleDto: UpdateScheduleDto,
|
||||
deviceType: ProductType,
|
||||
): Promise<addScheduleDeviceInterface> {
|
||||
try {
|
||||
const convertedTime = convertTimestampToDubaiTime(updateScheduleDto.time);
|
||||
@ -369,7 +399,10 @@ export class ScheduleService {
|
||||
value: updateScheduleDto.function.value,
|
||||
},
|
||||
],
|
||||
category: `category_${updateScheduleDto.category}`,
|
||||
category:
|
||||
deviceType == ProductType.CUR_2
|
||||
? updateScheduleDto.category
|
||||
: `category_${updateScheduleDto.category.replace('category_', '')}`,
|
||||
},
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user