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

16.67% Statements 4/24
0% Branches 0/14
12.5% Functions 1/8
16.67% Lines 4/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                                                                                                                           
'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,
      encodeQueryAsString = _ref.encodeQueryAsString;
 
  return {
    listCollections: function listCollections() {
      var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
 
      var expected = ['text', 'limit', 'offset', 'sort', 'sortdir'];
      var params = filterQuery.apply(undefined, [query].concat(expected));
 
      return client._.get('/collection', { params: params });
    },
    createCollection: function createCollection(collection) {
      var expected = ['name', 'description', 'public'];
      var params = filterQuery.apply(undefined, [collection].concat(expected));
 
      var _mustContain = mustContain.apply(undefined, [params].concat(expected)),
          missingKeys = _mustContain.missingKeys,
          promise = _mustContain.promise;
 
      return missingKeys ? promise : busy(client._.post('/collection' + encodeQueryAsString(params)));
    },
    deleteCollection: function deleteCollection(id) {
      return busy(client._.delete('/collection/' + id));
    },
    getCollection: function getCollection(id) {
      return busy(client._.get('/collection/' + id));
    },
    editCollection: function editCollection() {
      var collection = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
 
      var expected = ['name', 'description'];
      var params = filterQuery.apply(undefined, [collection].concat(expected));
 
      var _mustContain2 = mustContain(collection, '_id'),
          missingKeys = _mustContain2.missingKeys,
          promise = _mustContain2.promise;
 
      return missingKeys ? promise : busy(client._.put('/collection/' + collection._id + encodeQueryAsString(params)));
    },
    getCollectionAccess: function getCollectionAccess(id) {
      return busy(client._.get('/collection/' + id + '/access'));
    },
    editCollectionAccess: function editCollectionAccess(collection) {
      var expected = ['access', 'public'];
      var params = filterQuery.apply(undefined, [collection].concat(expected));
 
      var _mustContain3 = mustContain(collection, '_id'),
          missingKeys = _mustContain3.missingKeys,
          promise = _mustContain3.promise;
 
      return missingKeys ? promise : busy(client._.put('/collection/' + collection._id + '/access' + encodeQueryAsString(params)));
    }
  };
};