index.ts 1.18 KB
export const formatTriggerData = (triggerData) => {
  const { triggerType, entityId, type1, type2, operation, value } = triggerData;
  return {
    triggerType,
    entityId,
    triggerCondition: {
      condition: [
        {
          key: {
            type: type1,
            key: type2,
          },
          valueType: 'NUMERIC',
          predicate: {
            type: 'NUMERIC',
            operation: operation,
            value: {
              defaultValue: Number(value),
            },
          },
        },
      ],
      spec: {
        type: 'SIMPLE',
      },
    },
  };
};

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