ng-base-service
Version:
BaseService is a service for angular API CRUD
133 lines (127 loc) • 3.15 kB
JavaScript
import { __awaiter } from 'tslib';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @abstract
* @template TEntity
*/
class BaseService {
/**
* @param {?} _http
* @param {?} url
*/
constructor(_http, url) {
this._http = _http;
this.url = url;
}
/**
* @param {?} id
* @return {?}
*/
getById(id) {
return this._http.get(`${this.url}/${id}`);
}
/**
* @return {?}
*/
getAll() {
return this._http.get(this.url);
}
/**
* @param {?} context
* @return {?}
*/
add(context) {
return this._http.post(this.url, context);
}
/**
* @param {?} id
* @param {?} context
* @return {?}
*/
update(id, context) {
return this._http.put(`${this.url}/${id}`, context);
}
/**
* @param {?} id
* @return {?}
*/
delete(id) {
return this._http.delete(`${this.url}/${id}`);
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @abstract
* @template TEntity
*/
class BaseAsyncService {
/**
* @param {?} _http
* @param {?} url
*/
constructor(_http, url) {
this._http = _http;
this.url = url;
}
/**
* @param {?} id
* @return {?}
*/
getById(id) {
return __awaiter(this, void 0, void 0, function* () {
return yield this._http.get(`${this.url}/${id}`).toPromise();
});
}
/**
* @return {?}
*/
getAll() {
return __awaiter(this, void 0, void 0, function* () {
return yield this._http.get(this.url).toPromise();
});
}
/**
* @param {?} context
* @return {?}
*/
add(context) {
return __awaiter(this, void 0, void 0, function* () {
return yield this._http.post(this.url, context).toPromise();
});
}
/**
* @param {?} id
* @param {?} context
* @return {?}
*/
update(id, context) {
return __awaiter(this, void 0, void 0, function* () {
return yield this._http.put(`${this.url}/${id}`, context).toPromise();
});
}
/**
* @param {?} id
* @return {?}
*/
delete(id) {
return __awaiter(this, void 0, void 0, function* () {
return yield this._http.delete(`${this.url}/${id}`).toPromise();
});
}
}
/**
* @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