index.ts 1.27 KB
export const formatTriggerData = (m) => {
  return {
    triggerType: m?.triggerType,
    entityId: m?.entityId || m?.entityId1 || m?.entityId2,
    triggerCondition: {
      condition: [
        {
          key: {
            key: m.type2 == null ? 'CO2' : m.type2,
            type: m.type1 == null ? 'TIME_SERIES' : m.type1,
          },
          valueType: 'NUMERIC',
          predicate: {
            type: 'NUMERIC',
            value: {
              defaultValue: Number(m.value),
            },
            operation: m.operation == null ? 'EQUAL' : m.operation,
          },
        },
      ],
      spec: {
        type: 'SIMPLE',
      },
    },
  };
};

export const formatConditionData = (m) => {
  return {
    triggerType: m?.triggerType,
    entityId: m?.entityId,
    triggerCondition: {
      condition: [
        {
          key: {
            key: m.type == null ? 'CO2' : m.type,
            type: 'TIME_SERIES',
          },
          valueType: 'NUMERIC',
          // value: {},
          predicate: {
            type: 'NUMERIC',
            value: {
              defaultValue: Number(m.value) == null ? 0 : Number(m.value),
            },
            operation: m.operation,
          },
        },
      ],
      spec: {
        type: 'SIMPLE',
      },
    },
  };
};