github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/Decentralized-Energy-Composer-master/angular-app/src/app/Bank/Bank.service.ts (about) 1 import { Injectable } from '@angular/core'; 2 import { DataService } from '../data.service'; 3 import { Observable } from 'rxjs/Observable'; 4 import { Bank } from '../org.decentralized.energy.network'; 5 6 import { Cash } from '../org.decentralized.energy.network'; 7 import { Coins } from '../org.decentralized.energy.network'; 8 9 import 'rxjs/Rx'; 10 11 // Can be injected into a constructor 12 @Injectable() 13 export class BankService { 14 15 //define namespace strings for api calls 16 private BANK: string = 'Bank'; 17 private COINS: string = 'Coins'; 18 private CASH: string = 'Cash'; 19 20 //use data.service.ts to create services to make API calls 21 constructor(private residentService: DataService<Bank>, private coinsService: DataService<Coins>, private cashService: DataService<Cash>) { 22 }; 23 24 //get all bank objects on the blockchain network 25 public getAllBanks(): Observable<Bank[]> { 26 return this.residentService.getAll(this.BANK); 27 } 28 29 //get bank by id 30 public getBank(id: any): Observable<Bank> { 31 return this.residentService.getSingle(this.BANK, id); 32 } 33 34 //add bank 35 public addBank(itemToAdd: any): Observable<Bank> { 36 return this.residentService.add(this.BANK, itemToAdd); 37 } 38 39 //delete bank 40 public deleteBank(id: any): Observable<Bank> { 41 return this.residentService.delete(this.BANK, id); 42 } 43 44 //update bank 45 public updateBank(id: any, itemToUpdate: any): Observable<Bank> { 46 return this.residentService.update(this.BANK, id, itemToUpdate); 47 } 48 49 //coins functions 50 public getAllCoins(): Observable<Coins[]> { 51 return this.coinsService.getAll(this.COINS); 52 } 53 54 public getCoins(id: any): Observable<Coins> { 55 return this.coinsService.getSingle(this.COINS, id); 56 } 57 58 public addCoins(itemToAdd: any): Observable<Coins> { 59 return this.coinsService.add(this.COINS, itemToAdd); 60 } 61 62 public updateCoins(id: any, itemToUpdate: any): Observable<Coins> { 63 return this.coinsService.update(this.COINS, id, itemToUpdate); 64 } 65 66 public deleteCoins(id: any): Observable<Coins> { 67 console.log(id) 68 return this.coinsService.delete(this.COINS, id); 69 } 70 71 //cash functions 72 public getAllCash(): Observable<Cash[]> { 73 return this.cashService.getAll(this.CASH); 74 } 75 76 public getCash(id: any): Observable<Cash> { 77 return this.cashService.getSingle(this.CASH, id); 78 } 79 80 public addCash(itemToAdd: any): Observable<Cash> { 81 return this.cashService.add(this.CASH, itemToAdd); 82 } 83 84 public updateCash(id: any, itemToUpdate: any): Observable<Cash> { 85 return this.cashService.update(this.CASH, id, itemToUpdate); 86 } 87 88 public deleteCash(id: any): Observable<Cash> { 89 console.log(id) 90 return this.cashService.delete(this.CASH, id); 91 } 92 93 }