github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/Decentralized-Energy-Composer-master/angular-app/src/app/Coins/Coins.service.ts (about)

     1  import { Injectable } from '@angular/core';
     2  import { DataService } from '../data.service';
     3  import { Observable } from 'rxjs/Observable';
     4  import { Coins } from '../org.decentralized.energy.network';
     5  import 'rxjs/Rx';
     6  
     7  // Can be injected into a constructor
     8  @Injectable()
     9  export class CoinsService {
    10  
    11      //define namespace for api calls
    12  		private NAMESPACE: string = 'Coins';
    13  	
    14      //use data.service.ts to create services to make API calls
    15      constructor(private dataService: DataService<Coins>) {
    16      };
    17  
    18      //get all coins asset objects on the blockchain network
    19      public getAll(): Observable<Coins[]> {
    20          return this.dataService.getAll(this.NAMESPACE);
    21      }
    22  
    23      //get coins asset by id
    24      public getAsset(id: any): Observable<Coins> {
    25        return this.dataService.getSingle(this.NAMESPACE, id);
    26      }
    27  
    28      //add coins asset
    29      public addAsset(itemToAdd: any): Observable<Coins> {
    30        return this.dataService.add(this.NAMESPACE, itemToAdd);
    31      }
    32  
    33  }