createUrl.js 1.45 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"use strict";

const BASE_URL = "http://193.196.39.91:8080/frost-icity-tp31/v1.1";

/**
 * Create a temporal filter string for the fetched Observations
 * @param {String} dateStart Start date in YYYY-MM-DD format
 * @param {String} dateStop Stop date in YYYY-MM-DD format
 * @returns {String} Temporal filter string
 */
const createTemporalFilterString = function (dateStart, dateStop) {
  if (!dateStart || !dateStop) return;
  return `resultTime ge ${dateStart}T00:00:00.000Z and resultTime le ${dateStop}T00:00:00.000Z`;
};

/**
 * Create a query parameter object that should be sent together with a HTTP GET request using the Axios library
 * @param {String} dateStart Start date (for temporal filter) in YYYY-MM-DD format
 * @param {String} dateStop Stop date (for temporal filter) in YYYY-MM-DD format
 * @returns {Object} A query parameter object
 */
const createUrlParametersForGetRequest = function (dateStart, dateStop) {
  const QUERY_PARAM_RESULT_FORMAT = "dataArray";
  const QUERY_PARAM_ORDER_BY = "phenomenonTime asc";
  const QUERY_PARAM_FILTER = createTemporalFilterString(dateStart, dateStop);
  const QUERY_PARAM_SELECT = "result,phenomenonTime";

  return {
    "$resultFormat": QUERY_PARAM_RESULT_FORMAT,
    "$orderBy": QUERY_PARAM_ORDER_BY,
    "$filter": QUERY_PARAM_FILTER,
    "$select": QUERY_PARAM_SELECT,
  };
};

const QUERY_PARAMS_COMBINED = createUrlParametersForGetRequest(
  "2020-01-01",
  "2021-01-01"
);

export { BASE_URL, QUERY_PARAMS_COMBINED };