0

I'm using Loopback 3 to create API, I have model like this

Section.js

enter image description here

Section.json

enter image description here

Output

enter image description here

I want to subtract start_date to -7 hours so that it becomes like this

...
"start_date": "2019-06-23T17:00:00.000Z",
...

I try using getter from this thread How do I create getter and setter overrides? like this

enter image description here

but nothing has changed, did I implement it wrong?

Andi Siswanto
  • 59
  • 1
  • 1
  • 10

1 Answers1

1

Yes Now you have to call the Section.setup() at the end. This is the default User model.

So basically,

module.exports = function(User) {


  User.setup = function() {
    // We need to call the base class's setup method
    User.base.setup.call(this);
    var UserModel = this;
    UserModel.setter.email = function(value) {
      if (!UserModel.settings.caseSensitiveEmail) {
        this.$email = value.toLowerCase();
      } else {
        this.$email = value;
      }
    };

    return UserModel;
  };

  /*!
   * Setup the base user.
   */

  User.setup();
};

I don't know properly how to do that, but I made one MCVE that seemed to work(with bugs):

module.exports = function(Some) {
    Some.setup = function() {
        Some.base.setup.call(this);
        var UserModel = this;
        Some.getter.name = function(){
            console.log(this.$name);
            return this.$name+"lol";
        }
    }
    Some.setup();
};
Aritra Chakraborty
  • 12,123
  • 3
  • 26
  • 35