BigchainDB Javascript ORM - Retrieving all and appending to existing asset

367 Views Asked by At

I'm using an Node.js API application to handle BigchainDB assets.

Problem 1: Retrieve all assets of a model

Problem 2: Append ("Update") an existing assets

System: Node.js v8.11.2, npm v5.6.0, node module "express" v4.16.3, node module "babel-register" v6.26.0, node module bigchaindb-orm v.2.0.0

Creating asset / retrieving single asset

I set up an app in my BigchainDB test account (https://test.bigchaindb.com/). Creating an asset, using the BigchainDB ORM Javascript driver is no problem:

exports.create_an_entry = function(req, res) {
    bdbOrm.models.myModel
        .create({
            keypair: aliceKeypair,
            data: {
                city: req.body.city,
                Created_data: new Date().toString(),
            }
        })
        .then(asset => {
            res.json(asset)
        });
}

It is also no problem to retrive the info of an specific asset:

exports.read_an_entry = function(req, res) {
  bdbOrm.models.myModel
    .retrieve(req.params.assetId)
    .then(assets => {
        res.json(assets)
    })
}

Problem 1:

Using the model name "myModel" and retrieving all assets, leads to the error message

{ message: 'HTTP Error: Requested page not reachable', status: '429 Too Many Requests', requestURI: 'https://test.bigchaindb.com/api/v1/transactions?asset_id=' }

exports.list_all_data = function(req, res) {
    bdbOrm.models.myModel
        .retrieve()
        .then(assets => {
            res.json(assets)
        })
}

First, there are way more assets retrieved than I created. Second, when I'm skimming the requestURI's, there are assets with data I never created (e.g. "name": "Robin", "email": "[email protected]") When I change the model name to "testung" I only recieve assets I created under this model name.

Must the model name be unique, even accross applications?

Problem 2:

In the "append" operation examples, there is created an asset and then appended new data to this, in the same step. Following the example I get as output one asset with an unique ID and two operations in the "transactionHistory". One CREATE operation with the initial data and one TRANSFER operation with the new data.

But what I want is to append changed/new data to an already created asset. For example an asset is created, where a car costs $10.000. After some time the owner decides, that the car should cost $9.000. The following code won't work:

exports.update_an_entry = function(req, res) {
    bdbOrm.models.myModel
       .retrieve(req.params.assetId)
       .then(asset => {
           return asset.append({
               toPublicKey: aliceKeypair.publicKey,
               keypair: aliceKeypair,
               data: {
                   price: req.params.price,
               }
           })
       })
       .then(updatedAsset => {
           res.json(updatedAsset)
       })
}

What am I doing wrong or am I getting the concept of BigchainDB fundamentally wrong?

Btw. the CRAB tutorial isn't working, it responses with an status "400 BAD REQUEST": https://tutorials.bigchaindb.com/crab/

0

There are 0 best solutions below