Source: components/restmodules/ParametersRestModule.js

import isUUID from 'validator/lib/isUUID';
import { API } from '../../LocalConfiguration';
import { handleErrors, errors} from "./RestModuleAPI";

const monitoredAreaPath = API + '/areas/';
/**
 * Parameters Rest API
 * @module ParametersRestModule
 */

/**
 *
 * @param areaId
 * @returns {Promise<void | never>}
 */
export function fetchMonitoredAreaParameters(areaId) {
  if (!isUUID(areaId)) {
    throw new Error(errors.invalidUUI);
  }

  return fetch(monitoredAreaPath + areaId + "/detection_params")
  .then(response => handleErrors(response))
  .then(response => response.json());
}

/**
 *
 *
 * @param areaId
 * @param params
 * @returns {Promise<Response | never>}
 */
export function updateMonitoredAreaParameters(areaId, params) {
  return fetch(monitoredAreaPath + areaId + "/detection_params", {
    method: 'PUT',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(params)
  }).then(response => response.json());
}