all files / src/network/remote/ simulations.js

37.5% Statements 9/24
0% Branches 0/18
16.67% Functions 2/12
37.5% Lines 9/24
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83                                                                                                                                                   
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
 
exports.default = function (_ref) {
  var client = _ref.client,
      filterQuery = _ref.filterQuery,
      mustContain = _ref.mustContain,
      busy = _ref.busy;
 
  return {
    getSimulation: function getSimulation(id) {
      return busy(client._.get('/simulations/' + id));
    },
    editSimulation: function editSimulation(simulation) {
      var expected = ['name', 'description', 'active', 'disabled', 'metadata', 'steps'];
      var sfiltered = filterQuery.apply(undefined, [simulation].concat(expected));
 
      return busy(client._.patch('/simulations/' + simulation._id, sfiltered, {
        headers: headers,
        transformRequest: _utils.transformRequest
      }));
    },
    deleteSimulation: function deleteSimulation(id) {
      return busy(client._.delete('/simulations/' + id));
    },
    cloneSimulation: function cloneSimulation(id, _ref2) {
      var _ref2$name = _ref2.name,
          name = _ref2$name === undefined ? 'Cloned simulation' : _ref2$name;
 
      return busy(client._.post('/simulations/' + id + '/clone'), { name: name }, { headers: headers, transformRequest: _utils.transformRequest });
    },
    downloadSimulation: function downloadSimulation(id) {
      return busy(client._.get('/simulations/' + id + '/download'));
    },
    getSimulationStep: function getSimulationStep(id, name) {
      return busy(client._.get('/simulations/' + id + '/steps/' + name));
    },
    updateSimulationStep: function updateSimulationStep(id, name, step) {
      return busy(client._.patch('/simulations/' + id + '/steps/' + name, step, {
        headers: headers,
        transformRequest: _utils.transformRequest
      }));
    },
    getSimulationAccess: function getSimulationAccess(_id) {
      return busy(client._.get('/simulations/' + _id + '/access'));
    },
    setSimulationAccess: function setSimulationAccess(_id, users, groups) {
      var level = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
      var flags = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
 
      return busy(client._.put('/simulations/' + _id + '/access', {
        users: users,
        groups: groups,
        level: parseInt(level, 10),
        flags: flags
      }));
    },
    patchSimulationAccess: function patchSimulationAccess(_id, users, groups) {
      var level = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
      var flags = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
 
      return busy(client._.patch('/simulations/' + _id + '/access', {
        users: users,
        groups: groups,
        level: parseInt(level, 10),
        flags: flags
      }));
    },
    revokeSimulationAccess: function revokeSimulationAccess(_id, users, groups) {
      return busy(client._.patch('/simulations/' + _id + '/access/revoke', { users: users, groups: groups }));
    }
  };
};
 
var _utils = require('./utils');
 
var headers = {
  'Content-Type': 'application/json'
};