github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/build-blockchain-insurance-app-master/web/www/blockchain/repairShopPeer.js (about) 1 'use strict'; 2 3 import config from './config'; 4 import { wrapError } from './utils'; 5 import { repairShopClient as client, isReady } from './setup'; 6 7 export async function getRepairOrders() { 8 if (!isReady()) { 9 return; 10 } 11 try { 12 const repairOrders = await query('repair_order_ls'); 13 return repairOrders; 14 } catch (e) { 15 throw wrapError(`Error getting repair orders: ${e.message}`, e); 16 } 17 } 18 19 export async function completeRepairOrder(uuid) { 20 if (!isReady()) { 21 return; 22 } 23 try { 24 const successResult = await invoke(`repair_order_complete`, { uuid }); 25 if (successResult) { 26 throw new Error(successResult); 27 } 28 } catch (e) { 29 throw wrapError(`Error marking repair order as complete: ${e.message}`, e); 30 } 31 } 32 33 export function getBlocks(noOfLastBlocks) { 34 return client.getBlocks(noOfLastBlocks); 35 } 36 37 export const on = client.on.bind(client); 38 export const once = client.once.bind(client); 39 export const addListener = client.addListener.bind(client); 40 export const prependListener = client.prependListener.bind(client); 41 export const removeListener = client.removeListener.bind(client); 42 43 function invoke(fcn, ...args) { 44 return client.invoke( 45 config.chaincodeId, config.chaincodeVersion, fcn, ...args); 46 } 47 48 function query(fcn, ...args) { 49 return client.query( 50 config.chaincodeId, config.chaincodeVersion, fcn, ...args); 51 }