UNPKG

baasic-sdk-angular

Version:

Angular (v5+) SDK provides core functionality for building web and mobile applications on [Baasic](http://www.baasic.com/).

536 lines (535 loc) 31.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var core_1 = require("@angular/core"); var index_1 = require("../index"); var MeteringService = /** @class */ (function () { function MeteringService(baasicApp) { this.baasicApp = baasicApp; } /** * Returns a promise that is resolved once the find action has been performed. Success response returns a list of metering resources matching the given criteria. * @method * @param options Query resource options object. * @returns A promise that is resolved once the find action has been performed. * @example MeteringService.find({ pageNumber : 1, pageSize : 10, orderBy : '<field>', orderDirection : '<asc|desc>', categories: 'Storage,Requests,Bandwidth' }) .then(function (collection) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ MeteringService.prototype.find = function (options) { return this.baasicApp.meteringModule.find(options); }; /** * Returns a promise that is resolved once the get action has been performed. Success response returns the metering resource. * @method * @param id MeteringData id which uniquely identifies MeteringData resource that needs to be retrieved. * @param options Query resource options object. * @returns A promise that is resolved once the get action has been performed. * @example MeteringService.get() .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ MeteringService.prototype.get = function (id, options) { return this.baasicApp.meteringModule.get(id, options); }; /** * Returns a promise that is resolved once the create metering action has been performed; this action creates a new metering resource. * @method * @param data An MeteringData object that needs to be inserted into the system. * @returns A promise that is resolved once the create metering action has been performed * @example MeteringService.create({ category : '<category-name>', name : '<sub-category-name>', value: '<value>' }) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ MeteringService.prototype.create = function (data) { return this.baasicApp.meteringModule.create(data); }; /** * Returns a promise that is resolved once the update metering action has been performed; this action updates a metering resource. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicMeteringRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapper.updateParams(meteringData); * let uri = params['model'].links('put').href; * ``` * @method * @param data An metering data object used to update specified MeteringData resource. * @returns A promise that is resolved once the update metering action has been performed. * @example // meteringData is a resource previously fetched using get action. meteringData.value = '<some-new-value>'; MeteringService.update(meteringData) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ MeteringService.prototype.update = function (data) { return this.baasicApp.meteringModule.update(data); }; /** * Returns a promise that is resolved once the remove action has been performed. This action will remove a metering resource from the system if successfully completed. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicMeteringRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapper.removeParams(meteringData); * let uri = params['model'].links('delete').href; * ``` * @method * @param data An metering data object used to remove specified MeteringData resource. * @returns A promise that is resolved once the remove action has been performed. * @example // meteringData is a resource previously fetched using get action. MeteringService.remove(meteringData) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ MeteringService.prototype.remove = function (data) { return this.baasicApp.meteringModule.remove(data); }; /** * Returns a promise that is resolved once the purge action has been performed. This action will remove all metering resources from the system if successfully completed. * @method * @returns A promise that is resolved once the purge action has been performed. * @example MeteringService.purge() .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ MeteringService.prototype.purge = function () { return this.baasicApp.meteringModule.purge(); }; Object.defineProperty(MeteringService.prototype, "batch", { get: function () { var baasicApp = this.baasicApp; return { /** * Returns a promise that is resolved once the create data action has been performed; this action creates new data resources. * @method * @param data An MeteringData objects that need to be inserted into the system. * @returns A promise that is resolved once the create data action has been performed. * @example MeteringService.batch.create([{ applicationId : '<applicationId>', category : '<category>', name: '<name>', value: '<value>' }]) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ create: function (data) { return baasicApp.meteringModule.batch.create(data); }, /** * Returns a promise that is resolved once the update data action has been performed; this action updates specified data resources. * @method * @param data An MeteringData objects used to update specified MeteringData resources. * @returns A promise that is resolved once the update data action has been performed. * @example MeteringService.batch.update(companies) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ update: function (data) { return baasicApp.meteringModule.batch.update(data); }, /** * Returns a promise that is resolved once the remove action has been performed. This action will remove data resources from the system if successfully completed. * @method * @param ids MeteringData ids which uniquely identify MeteringData resources that need to be deleted. * @returns A promise that is resolved once the remove action has been performed. * @example MeteringService.batch.remove(companyIds) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ remove: function (ids) { return baasicApp.meteringModule.batch.remove(ids); } }; }, enumerable: true, configurable: true }); Object.defineProperty(MeteringService.prototype, "statistics", { get: function () { var baasicApp = this.baasicApp; return { /** * Returns a promise that is resolved once the find action has been performed. Success response returns a list of metering resources matching the given criteria. * @method * @param options Query resource options object. * @returns A promise that is resolved once the find action has been performed. * @example MeteringService.statistics.find({ pageNumber : 1, pageSize : 10, orderBy : '<field>', orderDirection : '<asc|desc>', category: 'Requests', rateBy : '<minute,hour,day,week,month,year>', from: '2 days ago', to: 'now' }) .then(function (collection) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ find: function (options) { return baasicApp.meteringModule.statistics.find(options); } }; }, enumerable: true, configurable: true }); Object.defineProperty(MeteringService.prototype, "acl", { get: function () { var baasicApp = this.baasicApp; return { /** * Returns a promise that is resolved once the get action has been performed. Success response returns a list of ACL policies established for the specified metering resource. * @method * @param options Query resource options object. * @returns A promise that is resolved once the get action has been performed. * @example MeteringService.acl.get({id: '<id>'}) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ get: function (options) { return baasicApp.meteringModule.acl.get(options); }, /** * Returns a promise that is resolved once the update acl action has been performed, this action creates new ACL policy for the specified metering resource. * @method * @param options ACL options object. * @example let options = {id : '<id>'}; let aclObj = { actionId: '<action-id'>, roleId: '<roleId>', userId: '<userId>' }; options[baasicConstants.modelPropertyName] = aclObj; MeteringService.acl.update(options) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ update: function (options) { return baasicApp.meteringModule.acl.update(options); }, /** * Returns a promise that is resolved once the removeByUser action has been performed. This action deletes ACL policy assigned to the specified user and metering resource. * @method * @param id User metering data id which uniquely identifies user metering data resource whose security privileges need to be retrieved and updated. * @param action Action abbreviation which identifies ACL policy assigned to the specified user and user metering data resource. * Supported Values: * "Create" * "Delete" * "Read" * "Update" * @param user A value that uniquely identifies user for which ACL policy needs to be removed. * @param data ACL Policy object used to delete specified item in the system. * @returns A promise that is resolved once the removeByUser action has been performed. * @example MeteringService.acl.removeByUser('<id>', '<access-action>', '<username>') .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ removeByUser: function (id, action, user, data) { return baasicApp.meteringModule.acl.removeByUser(id, action, user, data); }, /** * Returns a promise that is resolved once the removeByRole action has been performed. This action deletes ACL policy assigned to the specified role and metering resource. * @method * @param id User metering data id which uniquely identifies user metering data resource whose security privileges need to be retrieved and updated. * @param action Action abbreviation which identifies ACL policy assigned to the specified user and user metering data resource. * Supported Values: * "Create" * "Delete" * "Read" * "Update" * @param role A value that uniquely identifies role for which ACL policy needs to be removed. * @param data ACL Policy object used to delete specified item in the system. * @returns A promise that is resolved once the removeByRole action has been performed. * @example MeteringService.acl.removeByRole('<id>', '<access-action>', '<role-name>') .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ removeByRole: function (id, action, role, data) { return baasicApp.meteringModule.acl.removeByRole(id, action, role, data); } }; }, enumerable: true, configurable: true }); Object.defineProperty(MeteringService.prototype, "settings", { get: function () { var baasicApp = this.baasicApp; return { /** * Returns a promise that is resolved once the get action has been performed. Success response returns the metering resource. * @method * @example baasicMeteringSettingsClient.get() .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ get: function (options) { return baasicApp.meteringModule.settings.get(options); }, /** * Returns a promise that is resolved once the update metering action has been performed; this action updates a metering resource. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicMeteringSettingsRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapper.updateParams(meteringSettings); * let uri = params['model'].links('put').href; * ``` * @method * @param data An meteringSetting object used to update specified MeteringSetting resource. * @returns A promise that is resolved once the update metering action has been performed. * @example // meteringSettings is a resource previously fetched using get action. meteringSettings.dataRetentionPeriod = 60; baasicMeteringSettingsClient.update(meteringSettings) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ update: function (data) { return baasicApp.meteringModule.settings.update(data); } }; }, enumerable: true, configurable: true }); Object.defineProperty(MeteringService.prototype, "category", { get: function () { var baasicApp = this.baasicApp; return { /** * Returns a promise that is resolved once the find action has been performed. Success response returns a list of metering resources matching the given criteria. * @method * @param options Query resource options object. * @returns A promise that is resolved once the find action has been performed. * @example MeteringService.category.find({ pageNumber : 1, pageSize : 10, orderBy : '<field>', orderDirection : '<asc|desc>', search : '<search-phrase>' }) .then(function (collection) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ find: function (options) { return baasicApp.meteringModule.category.find(options); }, /** * Returns a promise that is resolved once the get action has been performed. Success response returns the metering resource. * @method * @param id MeteringCategory id which uniquely identifies MeteringCategory resource that needs to be retrieved. * @param options Query resource options object. * @returns A promise that is resolved once the get action has been performed. * @example MeteringService.category.get(id) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ get: function (id, options) { return baasicApp.meteringModule.category.get(id, options); }, /** * Returns a promise that is resolved once the create metering action has been performed; this action creates a new metering resource. * @method * @param data An MeteringCategory object that needs to be inserted into the system. * @returns A promise that is resolved once the create metering action has been performed. * @example MeteringService.category.create({ category : '<category-name>', unitName : 'Kb', unitFactor: 1, defaultSamplingRate: '<value>', - Defaults: Minute = 1,Hour = 2,Day = 3,Week = 4,Month = 5,Year = 6 aggregateFunction: '<value>' - Defaults: None = 0,Count = 1,Avg = 2,Max = 3,Min = 4,Sum = 5 }) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ create: function (data) { return baasicApp.meteringModule.category.create(data); }, /** * Returns a promise that is resolved once the update metering action has been performed; this action updates a metering resource. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicMeteringCategoryRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapepr.updateParams(meteringCategory); * let uri = params['model'].links('put').href; * ``` * @method * @param data An meteringCategory object used to update specified MeteringCategory resource. * @returns A promise that is resolved once the remove action has been performed. * @example // meteringCategory is a resource previously fetched using get action. meteringCategory.defaultSamplingRate = 'Day'; MeteringService.category.update(meteringCategory) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ update: function (data) { return baasicApp.meteringModule.category.update(data); }, /** * Returns a promise that is resolved once the remove action has been performed. This action will remove a metering resource from the system if successfully completed. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicMeteringCategoryRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapper.removeParams(meteringCategory); * let uri = params['model'].links('delete').href; * ``` * @method * @param data An meteringCategory object used to update specified MeteringCategory resource. * @returns A promise that is resolved once the remove action has been performed. * @example // meteringCategory is a resource previously fetched using get action. MeteringService.category.remove(meteringCategory) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ remove: function (data) { return baasicApp.meteringModule.category.remove(data); }, batch: { /** * Returns a promise that is resolved once the create category action has been performed; this action creates new category resources. * @method * @param data An MeteringCategory objects that need to be inserted into the system. * @returns A promise that is resolved once the create category action has been performed. * @example MeteringService.category.batch.create([{ aggregateFunction : '<aggregateFunction>', category : '<name>', defaultSamplingRate: '<defaultSamplingRate>', slug: '<slug>', unitFactor: '<unitFactor>', unitName: '<unitName>' }]) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ create: function (data) { return baasicApp.meteringModule.category.batch.create(data); }, /** * Returns a promise that is resolved once the update category action has been performed; this action updates specified category resources. * @method * @param data An MeteringCategory objects used to update specified MeteringCategory resources. * @returns A promise that is resolved once the update category action has been performed. * @example MeteringService.category.batch.update(companies) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ update: function (data) { return baasicApp.meteringModule.category.batch.update(data); }, /** * Returns a promise that is resolved once the remove action has been performed. This action will remove category resources from the system if successfully completed. * @method * @param ids MeteringCategory ids which uniquely identify MeteringCategory resources that need to be deleted. * @returns A promise that is resolved once the remove action has been performed. * @example MeteringService.category.batch.remove(companyIds) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ delete: function (ids) { return baasicApp.meteringModule.category.batch.delete(ids); } } }; }, enumerable: true, configurable: true }); MeteringService = tslib_1.__decorate([ core_1.Injectable(), tslib_1.__metadata("design:paramtypes", [index_1.BaasicAppService]) ], MeteringService); return MeteringService; }()); exports.MeteringService = MeteringService;