getting Error: Expected a Resource or Concept have checked older posts too but it's not helping me out with my code

时光怂恿深爱的人放手 提交于 2019-12-08 03:32:50

问题


I have two transactions GoodsMovement and Payment, Goodsmovement will track delivery of Goods and Payment transaction will check for payments if goods are delivered.

I'm working on below code:

    /**
 * New model file
 */

namespace org.acme.paysystem

enum PaymentStatus{
o PARTIALLY_PAID
o TOTAL_AMOUNT_PAID
o NOT_PAID
}

enum DeliveryStatus{
o DELIVERED
o IN_TRANSIT
}

asset Goods identified by billNo{
  o String billNo
  o Double billAmount
  o DateTime billDate
  o DeliveryStatus deliveryStatus
  o PaymentStatus paymentStatus default = 'NOT_PAID'
}

concept Address{
o String Country optional
o String City optional
o String Street optional
o String Zip optional
}

abstract participant user identified by email{
  o String email
  o String fname
  o String lname
  o Address address
}

participant Retailer extends user {
o String shopNo
o Double amountDue
o Double accountBalance
}

participant Distributor extends user{
o String PAN
o Double bankBalance
}

transaction Payment{
  --> Goods goods
  --> Retailer retailer
  --> Distributor distributor
  o PaymentStatus paymentStatus
}

transaction GoodsMovement {
  --> Goods goods
  o DeliveryStatus deliveryStatus

I haven't mentioned GoodsMovement transaction here since it's working as expected. 

Below is the Script file:

/**
* @param {org.acme.paysystem.Payment} Payment
* @transaction
*/
function Payment(Payment){
        var paymentRecievedFlag = 0;
        var amountRecieved = 0;
                if(GoodsMovement == 'IN_TRANSIT')
                    {
                         console.log("Goods are IN_TRANSIT");
                    }
          else
          {
            if ((Payment.retailer.accountBalance - Payment.goods.billAmount) > 0 ){
               Payment.retailer.accountbalance -= Payment.goods.billAmount;
               Payment.distributor.bankBalance += Payment.goods.billAmount;

              Payment.paymentStatus = 'TOTAL_AMOUNT_PAID';
              //Payment.goods.paymentStatus = 'TOTAL_AMOUNT_PAID';
          }

            else{
                  Payment.retailer.amountDue = Payment.goods.billAmount - Payment.retailer.accountBalance;
                  Payment.distributor.bankBalance += Payment.retailer.accountBalance;
                  Payment.paymentStatus = PARTIALLY_PAID;
            }}


          return getParticipantRegistry('org.acme.paysystem.Distributor')
               .then(function(distributorRegistry){
                  return distributorRegistry.update(Payment.distributer);
          })
               .then(function(){
                  return getParticipantRegistry('org.acme.paysystem.Retailer');
          })
               .then(function(retailerRegistry){
                  return retailerRegistry.update(Payment.retailer);
          })
                 .then(function(){
                       return getAssetRegistry('org.acme.paysystem.Goods');
          })
                 .then(function(goodsRegistry){
                        return goodsRegistry.update(Payment.goods);
          });       
}

I have checked properly and search through Internet too but I'm not able to figure it out what's the problem with my code. Thanks if anyone could help me out with code


回答1:


line x should be:

  if(Payment.goods.deliveryStatus == 'IN_TRANSIT')

line 31 should be:

 return distributorRegistry.update(Payment.distributor);

line 18 and 25 should refer to: Payment.goods.paymentStatus = 'TOTAL_AMOUNT_PAID';

not Payment.paymentStatus

line 25 needs quotes: Payment.goods.paymentStatus = 'PARTIALLY_PAID';

Then using this transaction - it worked:

{
  "$class": "org.acme.paysystem.Payment",
  "goods": "resource:org.acme.paysystem.Goods#1",
  "retailer": "resource:org.acme.paysystem.Retailer#a@b.com",
  "distributor": "resource:org.acme.paysystem.Distributor#a@b.com",
  "paymentStatus": "PARTIALLY_PAID"
}


来源:https://stackoverflow.com/questions/48879731/getting-error-expected-a-resource-or-concept-have-checked-older-posts-too-but-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!