All files / js/api/geonode/adapter index.js

100% Statements 12/12
83.33% Branches 10/12
100% Functions 4/4
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60                                            1x 3x 3x 3x           2x 2x                     1x 2x 2x 2x         2x 2x              
/*
 * Copyright 2020, GeoSolutions Sas.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree.
 */
 
import axios from '@mapstore/framework/libs/ajax';
import { getConfigProp } from '@mapstore/framework/utils/ConfigUtils';
import { parseDevHostname } from '@js/utils/APIUtils';
 
/**
* Api for GeoNode MapStore adapter
* @name api.geonode.adapter
*/
 
/**
* Create a new MapStore map configuration
* @memberof api.geonode.adapter
* @param {object} body new map configuration
* @return {promise} it returns an object with the success map object response
*/
export const creatMapStoreMap = (body = {}) => {
    const baseUrl = getConfigProp('genode_rest_api') || '/mapstore/rest/';
    return axios.post(parseDevHostname(`${baseUrl}resources/`),
        body,
        {
            timeout: 10000,
            params: {
                full: true
            }
        })
        .then(({ data }) => data);
};
 
/**
* Update an existing MapStore map configuration
* @memberof api.geonode.adapter
* @param {number|string} id resource id
* @param {object} body map configuration
* @return {promise} it returns an object with the success map object response
*/
export const updateMapStoreMap = (id, body = {}) => {
    const baseUrl = getConfigProp('genode_rest_api') || '/mapstore/rest/';
    return axios.patch(parseDevHostname(`${baseUrl}resources/${id}/`),
        body,
        {
            params: {
                full: true
            }
        })
        .then(({ data }) => data);
};
 
export default {
    creatMapStoreMap,
    updateMapStoreMap
};