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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const SN_1 = require("../SN"); const _1 = require("./"); class ODataApi { constructor(_repository) { this._repository = _repository; this.Delete = (id, permanent) => this._repository.Ajax(`/content(${id})`, 'DELETE', Object, { permanent }).share(); this.Upload = (path, data, creation) => { let url = `${SN_1.ODataHelper.getContentURLbyPath(path)}/Upload`; if (creation) { url = `${url}?create=1`; } else { url = url; } return this._repository.Ajax(url, 'POST', Object, data); }; } Get(options) { return this._repository.Ajax(`${options.path}?${SN_1.ODataHelper.buildUrlParamString(this._repository.Config, options.params)}`, 'GET').share(); } Fetch(options) { return this._repository.Ajax(`${options.path}?${SN_1.ODataHelper.buildUrlParamString(this._repository.Config, options.params)}`, 'GET').share(); } Post(path, contentBody) { contentBody.__ContentType = contentBody.Type; return this._repository .Ajax(SN_1.ODataHelper.getContentURLbyPath(path), 'POST', _1.ODataResponse, JSON.stringify(contentBody)) .map((resp) => resp.d) .share(); } Patch(id, fields) { const contentTypeWithResponse = _1.ODataResponse; return this._repository.Ajax(`/content(${id})`, 'PATCH', contentTypeWithResponse, `models=[${JSON.stringify(fields)}]`) .map((result) => result.d); } Put(id, fields) { const contentTypeWithResponse = _1.ODataResponse; return this._repository.Ajax(`/content(${id})`, 'PUT', contentTypeWithResponse, `models=[${JSON.stringify(fields)}]`) .map((result) => result.d); } CreateCustomAction(actionOptions, options, returns) { const returnsType = returns || Object; const action = new _1.CustomAction(actionOptions); const cacheParam = (action.noCache) ? '' : '&nocache=' + new Date().getTime(); let path = ''; if (typeof action.id !== 'undefined') { path = SN_1.ODataHelper.joinPaths(SN_1.ODataHelper.getContentUrlbyId(action.id), action.name); } else if (action.path) { path = SN_1.ODataHelper.joinPaths(SN_1.ODataHelper.getContentURLbyPath(action.path), action.name); } else { const error = new Error('No Id or Path provided.'); this._repository.Events.Trigger.CustomActionFailed({ ActionOptions: actionOptions, ODataParams: options, ResultType: returnsType, Error: error }); throw error; } if (cacheParam.length > 0) { path = `${path}?${cacheParam}`; } if (path.indexOf('OData.svc(') > -1) { const start = path.indexOf('('); path = path.slice(0, start) + '/' + path.slice(start); } if (typeof action.isAction === 'undefined' || !action.isAction) { const ajax = this._repository.Ajax(path, 'GET', returnsType).share(); ajax.subscribe((resp) => { this._repository.Events.Trigger.CustomActionExecuted({ ActionOptions: actionOptions, ODataParams: options, Result: resp }); }, (err) => { this._repository.Events.Trigger.CustomActionFailed({ ActionOptions: actionOptions, ODataParams: options, ResultType: returnsType, Error: err }); }); return ajax; } else { if (typeof options !== 'undefined' && typeof options.data !== 'undefined') { const ajax = this._repository.Ajax(path, 'POST', returnsType, JSON.stringify(options.data)).share(); ajax.subscribe((resp) => { this._repository.Events.Trigger.CustomActionExecuted({ ActionOptions: actionOptions, ODataParams: options, Result: resp }); }, (err) => { this._repository.Events.Trigger.CustomActionFailed({ ActionOptions: actionOptions, ODataParams: options, ResultType: returnsType, Error: err }); }); return ajax; } else { const ajax = this._repository.Ajax(path, 'POST', returnsType).share(); ajax.subscribe((resp) => { this._repository.Events.Trigger.CustomActionExecuted({ ActionOptions: actionOptions, ODataParams: options, Result: resp }); }, (err) => { this._repository.Events.Trigger.CustomActionFailed({ ActionOptions: actionOptions, ODataParams: options, ResultType: returnsType, Error: err }); }); return ajax; } } } } exports.ODataApi = ODataApi; //# sourceMappingURL=ODataApi.js.map |