Polymerfire error pushing data

84 Views Asked by At

I am creating a contract between two users and structuring my database as stated bellow. The problem is that I am having issues creating the contract with both users user_id:true. I am not sure if I am taking the right approach. I am following the firebase documentation and structuring the contract as recommended.

my-firebase
|
-contracts
  |- contract-id
    |- user_id: true
    |- user_id: true
    |- amount: 1000
    |- isactive: true
    |- started: 148314234733

I am creating the contract:

var contractDetails = {
 this.contractor:true,
 this.freelancer:true,
 amount: 1000,
 isactive: true,
 started: 'eee'
};
2

There are 2 best solutions below

0
On BEST ANSWER

The problem is your use of this. If you are using ES6, you can use computed properties:

var contractDetails = {
  [this.contractor]: true,
  [this.freelancer]: true,
  amount: 1000,
  isactive: true
  started: this.timestamp
};

If you are not, you can do something like this, instead:

var contractDetails = {
  amount: 1000,
  isactive: true
  started: this.timestamp
};
contractDetails[this.contractor] = true;
contractDetails[this.freelancer] = true;
0
On

How to query only the "contract" that are "isactive" for a "user"
- contract-id --) isactive: "true"_user.uid // Combine data to create a single
- query --) order-by-child="[[queryHandler]]"

- contract-id --) add property `user_uid_contractor` bind to `user.uid`<br>

    -contracts
      |- contract-id
        |- user_uid_freelancer: user.uid
        |- user_uid_contractor: user.uid
        |- amount: 1000
        |- isactive: "true"_user.uid // Combine data to create a single query.
        |- started: 148314234733

Code Query Employee Contract

  <firebase-query
   app-name="vida"
   path="/contracts"
   data="{{mycontracts}}"
   order-by-child=""true_"[[queryHandler]]"
   equal-to="[[user.uid]]"></firebase-query>

       properties:{
       queryHandler // computed value that build the path
       }