mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 10:25:23 +00:00
added enums to replace constants
This commit is contained in:
@ -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,
|
||||
);
|
||||
|
Reference in New Issue
Block a user