Advertisement
Halakul

Untitled

Jun 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export default class ResourceConsumption {
  2.  
  3.   //@ngInject
  4.   constructor($q, $resource, vpcDomainConsumptionAuth) {
  5.     this.$resource = $resource;
  6.     this.vpcDomainConsumptionAuth = vpcDomainConsumptionAuth;
  7.  
  8.     this.deffer = $q.deffer;
  9.     this.promise = this.deffer.promise;
  10.     this.resource = null;
  11.  
  12.     this._createResource();
  13.   }
  14.  
  15.   query(params, data) {
  16.     let $promise = this.promise.then(() => this.resource.query(params, data).$promise);
  17.  
  18.     return {$promise};
  19.   }
  20.  
  21.   getResourceInfo(params) {
  22.     let $promise = this.promise.then(() => this.resource.getResourceInfo(params).$promise);
  23.  
  24.     return {$promise};
  25.   }
  26.  
  27.   _createResource() {
  28.     return this.vpcDomainConsumptionAuth.getInfo().then(({url}) => {
  29.       const URL = url + '/v1/resource/sel_project/:uuid/metric/:type/measures';
  30.       const PARAMS = {
  31.         uuid: '@uuid',
  32.         type: '@type'
  33.       };
  34.       const ACTIONS = {
  35.         query: {
  36.           method: 'GET',
  37.           isArray: true
  38.         },
  39.         getResourceInfo: {
  40.           method: 'GET',
  41.           url: url + '/v1/resource/sel_project/:uuid'
  42.         }
  43.       };
  44.  
  45.       this.resource = this.$resource(URL, PARAMS, ACTIONS);
  46.  
  47.       this.deffer.resolve(this.$resource);
  48.  
  49.       return this.promise;
  50.     });
  51.   }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement