lib/my-contract.js
/**
   * 
   * pourCup
   * 
   * Transaction used when pouring a cup of coffee at the event. Will
   * record who poured it, what time, what type of coffee, etc.
   * Users then can use this cupId later to get more details from the
   * blockchain about their beverage
   * @param cupId - the Id of the cup of coffee to be poured
   */
pourCup

Transaction used when pouring a cup of coffee at the event. Will
record who poured it, what time, what type of coffee, etc.
Users then can use this cupId later to get more details from the
blockchain about their beverage
@param cupId - the Id of the cup of coffee to be poured
pourCup Transaction used when pouring a cup of coffee at the event . Will record who poured it what time what type of coffee etc . Users then can use this cupId later to get more details from the blockchain about their beverage @param cupId - the Id of the cup of coffee to be poured
async pourCup(ctx, cupId, batchId, transactionId) {
    console.info('pourCup called');
    if (cupId.length <= 0) {
      throw new Error('Please enter the cupId');
    }
    let cupCoffee = {};
    cupCoffee.cupId = cupId;
    let coffeeAsBytes = await ctx.stub.getState(batchId);
    if (!coffeeAsBytes || coffeeAsBytes.length === 0) {
      return new Error(`${batchId} batch does not exist`);
    }
    cupCoffee.batchId = batchId;
    cupCoffee.transactionId = transactionId;
    console.info('pourCup called after transId');
    let drinkType = cupId.charAt(0);
    if (drinkType.toLowerCase() === 'c') {
      cupCoffee.drinkType = 'Iced';
    } else if (drinkType.toLowerCase() === 'e') {
      cupCoffee.drinkType = 'Hot';
    } else {
      cupCoffee.drinkType = 'Nitro';
    }
    console.info('pourCup called after drinktype');
    let barista = cupId.charAt(1);
    if (barista.toLowerCase === 'j') {
      cupCoffee.barista = 'Josh';
    } else {
      cupCoffee.barista = 'Siv';
    }
    let coop = cupId.charAt(2);
    if (coop.toLowerCase() === 'b') {
      cupCoffee.beanType = 'Ethiopian Natural Yirgacheffe';
    }
    console.info('pourCup called after after coop');
    let dateStr = new Date();
    dateStr = dateStr.toString();
    cupCoffee.lastPour = dateStr;
    console.info('pourCup called after after date');
    cupCoffee.class = 'org.ibm.coffee.pourCup';
    console.log('cupId')
    console.log(cupId)
    await ctx.stub.putState(cupId, Buffer.from(JSON.stringify(cupCoffee)));
    console.info('updated ledger with key: ' + cupId + 'and value: ');
    console.info(JSON.stringify(cupCoffee));
    return cupCoffee;
  }
async pourCup ( ctx , cupId , batchId , transactionId ) { console . info ( 'pourCup called' ) ; if ( cupId . length <= 0 ) { throw new Error ( 'Please enter the cupId' ) ; } let cupCoffee = { } ; cupCoffee . cupId = cupId ; let coffeeAsBytes = await ctx . stub . getState ( batchId ) ; if ( ! coffeeAsBytes || coffeeAsBytes . length === 0 ) { return new Error ( ` ${ batchId } ` ) ; } cupCoffee . batchId = batchId ; cupCoffee . transactionId = transactionId ; console . info ( 'pourCup called after transId' ) ; let drinkType = cupId . charAt ( 0 ) ; if ( drinkType . toLowerCase ( ) === 'c' ) { cupCoffee . drinkType = 'Iced' ; } else if ( drinkType . toLowerCase ( ) === 'e' ) { cupCoffee . drinkType = 'Hot' ; } else { cupCoffee . drinkType = 'Nitro' ; } console . info ( 'pourCup called after drinktype' ) ; let barista = cupId . charAt ( 1 ) ; if ( barista . toLowerCase === 'j' ) { cupCoffee . barista = 'Josh' ; } else { cupCoffee . barista = 'Siv' ; } let coop = cupId . charAt ( 2 ) ; if ( coop . toLowerCase ( ) === 'b' ) { cupCoffee . beanType = 'Ethiopian Natural Yirgacheffe' ; } console . info ( 'pourCup called after after coop' ) ; let dateStr = new Date ( ) ; dateStr = dateStr . toString ( ) ; cupCoffee . lastPour = dateStr ; console . info ( 'pourCup called after after date' ) ; cupCoffee . class = 'org.ibm.coffee.pourCup' ; console . log ( 'cupId' ) console . log ( cupId ) await ctx . stub . putState ( cupId , Buffer . from ( JSON . stringify ( cupCoffee ) ) ) ; console . info ( 'updated ledger with key: ' + cupId + 'and value: ' ) ; console . info ( JSON . stringify ( cupCoffee ) ) ; return cupCoffee ; }
pourCup
pourCup
//there needs to be a batch associated with the cup that is poured //get the first character of the cupId - this represents drink type //get the 2nd character of cupId - this represents the barista which poured the cup //get the 3nd character of cupId - this represents the co-op