added enums to replace constants

This commit is contained in:
unknown
2024-10-06 15:44:49 +03:00
parent a5c1cad01c
commit 9a868c5757
68 changed files with 547 additions and 202 deletions

View File

@ -23,6 +23,11 @@ import {
GetAutomationByUnitInterface,
} from '../interface/automation.interface';
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
import { SpaceType } from '@app/common/constants/space-type.enum';
import {
ActionExecutorEnum,
EntityTypeEnum,
} from '@app/common/constants/automation.enum';
@Injectable()
export class AutomationService {
@ -64,7 +69,7 @@ export class AutomationService {
);
for (const action of actions) {
if (action.action_executor === 'device_issue') {
if (action.action_executor === ActionExecutorEnum.DEVICE_ISSUE) {
const device = await this.deviceService.getDeviceByDeviceUuid(
action.entity_id,
false,
@ -76,7 +81,7 @@ export class AutomationService {
}
for (const condition of conditions) {
if (condition.entity_type === 'device_report') {
if (condition.entity_type === EntityTypeEnum.DEVICE_REPORT) {
const device = await this.deviceService.getDeviceByDeviceUuid(
condition.entity_id,
false,
@ -127,12 +132,12 @@ export class AutomationService {
where: {
uuid: unitUuid,
spaceType: {
type: 'unit',
type: SpaceType.UNIT,
},
},
relations: ['spaceType'],
});
if (!unit || !unit.spaceType || unit.spaceType.type !== 'unit') {
if (!unit || !unit.spaceType || unit.spaceType.type !== SpaceType.UNIT) {
throw new BadRequestException('Invalid unit UUID');
}
return {
@ -240,7 +245,7 @@ export class AutomationService {
}));
for (const action of actions) {
if (action.actionExecutor === 'device_issue') {
if (action.actionExecutor === ActionExecutorEnum.DEVICE_ISSUE) {
const device = await this.deviceService.getDeviceByDeviceTuyaUuid(
action.entityId,
);
@ -249,8 +254,8 @@ export class AutomationService {
action.entityId = device.uuid;
}
} else if (
action.actionExecutor !== 'device_issue' &&
action.actionExecutor !== 'delay'
action.actionExecutor !== ActionExecutorEnum.DEVICE_ISSUE &&
action.actionExecutor !== ActionExecutorEnum.DELAY
) {
const sceneDetails = await this.getTapToRunSceneDetailsTuya(
action.entityId,
@ -268,7 +273,7 @@ export class AutomationService {
}));
for (const condition of conditions) {
if (condition.entityType === 'device_report') {
if (condition.entityType === EntityTypeEnum.DEVICE_REPORT) {
const device = await this.deviceService.getDeviceByDeviceTuyaUuid(
condition.entityId,
);