loopbackio / loopback-connector-redis

EXPERIMENTAL: Redis connector for LoopBack.
http://loopback.io/doc/en/lb2/Redis-connector.html
Other
36 stars 46 forks source link

Upserting an existing records returns all fields as strings #41

Open penguinpowernz opened 7 years ago

penguinpowernz commented 7 years ago

It will only display itself when you use the upsert route while specifying an ID:

This will not do it:

PUT /hvacs { installed: true, enabled: false}
---
{
  "installed": true,
  "enabled": false
}

But when you pass the ID to modify an existing:

PUT /hvacs { id: 1, installed: true, enabled: false}
---
{
  "installed": "true",
  "enabled": "false"
}

Even if the model doesn't already exist:

PUT /hvacs { id: 999, installed: true}
{
  "installed": "true",
  "id": 999
}
penguinpowernz commented 7 years ago

I narrowed it down to the ok() method in the BridgeToRedis.prototype.updateOrCreate method. Someone forgot to call fromDb on the resulting object to convert the fields to their various types.

This fixes it:

Need this at the head of the function:

  var self = this;

The change the ok function to this:

    function ok() {
      callback(error, self.fromDb(obj));
    }
penguinpowernz commented 7 years ago

Made a PR anyway..