ng-base-service
Version:
BaseService is a service for angular API CRUD
200 lines (194 loc) • 5.33 kB
JavaScript
import { __awaiter, __generator } from 'tslib';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @abstract
* @template TEntity
*/
var /**
* @abstract
* @template TEntity
*/
BaseService = /** @class */ (function () {
function BaseService(_http, url) {
this._http = _http;
this.url = url;
}
/**
* @param {?} id
* @return {?}
*/
BaseService.prototype.getById = /**
* @param {?} id
* @return {?}
*/
function (id) {
return this._http.get(this.url + "/" + id);
};
/**
* @return {?}
*/
BaseService.prototype.getAll = /**
* @return {?}
*/
function () {
return this._http.get(this.url);
};
/**
* @param {?} context
* @return {?}
*/
BaseService.prototype.add = /**
* @param {?} context
* @return {?}
*/
function (context) {
return this._http.post(this.url, context);
};
/**
* @param {?} id
* @param {?} context
* @return {?}
*/
BaseService.prototype.update = /**
* @param {?} id
* @param {?} context
* @return {?}
*/
function (id, context) {
return this._http.put(this.url + "/" + id, context);
};
/**
* @param {?} id
* @return {?}
*/
BaseService.prototype.delete = /**
* @param {?} id
* @return {?}
*/
function (id) {
return this._http.delete(this.url + "/" + id);
};
return BaseService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @abstract
* @template TEntity
*/
var /**
* @abstract
* @template TEntity
*/
BaseAsyncService = /** @class */ (function () {
function BaseAsyncService(_http, url) {
this._http = _http;
this.url = url;
}
/**
* @param {?} id
* @return {?}
*/
BaseAsyncService.prototype.getById = /**
* @param {?} id
* @return {?}
*/
function (id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._http.get(this.url + "/" + id).toPromise()];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**
* @return {?}
*/
BaseAsyncService.prototype.getAll = /**
* @return {?}
*/
function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._http.get(this.url).toPromise()];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**
* @param {?} context
* @return {?}
*/
BaseAsyncService.prototype.add = /**
* @param {?} context
* @return {?}
*/
function (context) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._http.post(this.url, context).toPromise()];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**
* @param {?} id
* @param {?} context
* @return {?}
*/
BaseAsyncService.prototype.update = /**
* @param {?} id
* @param {?} context
* @return {?}
*/
function (id, context) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._http.put(this.url + "/" + id, context).toPromise()];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**
* @param {?} id
* @return {?}
*/
BaseAsyncService.prototype.delete = /**
* @param {?} id
* @return {?}
*/
function (id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._http.delete(this.url + "/" + id).toPromise()];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
return BaseAsyncService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { BaseService, BaseAsyncService };
//# sourceMappingURL=ng-base-service.js.map