angular-odata-es5
Version:
OData service for Angular (es5 version)
93 lines • 4.53 kB
JavaScript
import { throwError } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { DeleteOperation, GetOperation, PatchOperation, PostOperation, PutOperation } from './angularODataOperation';
import { ODataQuery } from './angularODataQuery';
import { ODataUtils } from './angularODataUtils';
var ODataService = /** @class */ (function () {
function ODataService(_typeName, _http, config) {
this._typeName = _typeName;
this._http = _http;
this.config = config;
this._entitiesUri = config.getEntitiesUri(_typeName);
}
Object.defineProperty(ODataService.prototype, "TypeName", {
get: function () {
return this._typeName;
},
enumerable: true,
configurable: true
});
ODataService.prototype.Get = function (key) {
return new GetOperation(this._typeName, this.config, this._http, key);
};
ODataService.prototype.Post = function (entity) {
return new PostOperation(this._typeName, this.config, this._http, entity);
};
ODataService.prototype.Patch = function (entity, key) {
return new PatchOperation(this._typeName, this.config, this._http, key, entity);
};
ODataService.prototype.Put = function (entity, key) {
return new PutOperation(this._typeName, this.config, this._http, key, entity);
};
ODataService.prototype.Delete = function (key) {
return new DeleteOperation(this._typeName, this.config, this._http, key);
};
ODataService.prototype.CustomAction = function (key, actionName, postdata) {
var body = postdata ? JSON.stringify(postdata) : null;
return this._http.post(this.getEntityUri(key) + "/" + actionName, body, this.config.customRequestOptions).pipe(map(function (resp) { return resp; }));
};
ODataService.prototype.CustomCollectionAction = function (actionName, postdata) {
var body = postdata ? JSON.stringify(postdata) : null;
return this._http.post(this._entitiesUri + "/" + actionName, body, this.config.customRequestOptions).pipe(map(function (resp) { return resp; }));
};
ODataService.prototype.CustomFunction = function (key, functionName, parameters) {
if (parameters) {
var params = ODataUtils.convertObjectToString(parameters);
functionName = functionName + "(" + params + ")";
}
else if (!functionName.endsWith(')') && !functionName.endsWith('()')) {
functionName = functionName + "()";
}
return this._http.get(this.getEntityUri(key) + "/" + functionName, this.config.defaultRequestOptions).pipe(map(function (resp) { return resp; }));
};
ODataService.prototype.CustomCollectionFunction = function (functionName, parameters) {
if (parameters) {
var params = ODataUtils.convertObjectToString(parameters);
functionName = functionName + "(" + params + ")";
}
else if (!functionName.endsWith(')') && !functionName.endsWith('()')) {
functionName = functionName + "()";
}
return this._http.get(this._entitiesUri + "/" + functionName, this.config.defaultRequestOptions).pipe(map(function (resp) { return resp; }));
};
ODataService.prototype.ItemProperty = function (key, propertyName) {
return this._http.get(this.getEntityUri(key) + "/" + propertyName, this.config.defaultRequestOptions)
.pipe(map(function (r) { return r.body; }));
};
ODataService.prototype.Query = function () {
return new ODataQuery(this.TypeName, this.config, this._http);
};
ODataService.prototype.getEntityUri = function (key) {
return this.config.getEntityUri(key, this._typeName);
};
ODataService.prototype.handleResponse = function (entity) {
var _this = this;
return entity
.pipe(map(this.extractData), catchError(function (err, caught) {
if (_this.config.handleError) {
_this.config.handleError(err, caught);
}
return throwError(err);
}));
};
ODataService.prototype.extractData = function (res) {
if (res.status < 200 || res.status >= 300) {
throw new Error('Bad response status: ' + res.status);
}
var body = res.body;
return body || {};
};
return ODataService;
}());
export { ODataService };
//# sourceMappingURL=angularODataService.js.map