'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Licensed Materials - Property of IBM * IBM Business Analytics (C) Copyright IBM Corp. 2020 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['../../../lib/@waca/dashboard-common/dist/core/APIFactory', './api/ContentStoreAPI', 'underscore'], function (APIFactory, ContentStoreAPI, _) { var ContentStore = function () { function ContentStore(ajaxService) { _classCallCheck(this, ContentStore); this.ajaxService = ajaxService; this.baseObjectUrl = 'v1/objects'; } ContentStore.prototype.getAPI = function getAPI() { if (!this._api) { this._api = APIFactory.createAPI(this, [ContentStoreAPI]); } return this._api; }; ContentStore.prototype.get = function get() { var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '.my_folders'; var path = this._preparePath(id) + '/items?fields=id,type,defaultName,modificationTime,owner{defaultName,userName,email},version'; return this.ajaxService.get(path).then(function (response) { return response && response.data.map(function (item) { return { id: item.id, type: item.type, defaultName: item.defaultName, modificationTime: item.modificationTime, owner: { defaultName: _.isEmpty(item.owner) ? undefined : item.owner[0].defaultName, userName: _.isEmpty(item.owner) ? undefined : item.owner[0].userName, email: _.isEmpty(item.owner) ? undefined : item.owner[0].email }, version: item.version }; }) || []; }).catch(function (dfd, error) { return Promise.reject({ status: error.status }); }); }; ContentStore.prototype.delete = function _delete(id) { var path = this._preparePath(id) + '?force=true&recursive=true'; return this.ajaxService.delete(path).then().catch(function (dfd, error) { return Promise.reject({ status: error.status }); }); }; ContentStore.prototype.post = function post(id, content) { var path = this._preparePath(id) + '/items'; return this.ajaxService.post(path, { contentType: 'application/json', processData: false, dataType: 'text', data: JSON.stringify(content) }).then().catch(function (dfd, error) { return Promise.reject({ status: error.status }); }); }; ContentStore.prototype.put = function put(id, content) { var path = this._preparePath(id); return this.ajaxService.put(path, { contentType: 'application/json', processData: false, dataType: 'text', data: JSON.stringify(content) }).then().catch(function (dfd, error) { return Promise.reject({ status: error.status }); }); }; ContentStore.prototype._preparePath = function _preparePath(id) { return this.baseObjectUrl + '/' + id; }; return ContentStore; }(); return ContentStore; }); //# sourceMappingURL=ContentStore.js.map