How to override the basic user in a Strongloop loopback project?

Considering a new project created using

$ slc lb project myapp

How to replace the user model in models.jsonwith the client model placed in the directory ./models? Clients must have login / logout methods, etc. And "users" should not exist as an API. In addition, the client model does not have to be dynamic. Assume that the client should have a scheme:

  • name
  • Email
  • password
  • Question
  • answer
  • phone
  • verify
  • dataCreated

I have been playing with this for several days and my google-fu is letting me go. Any help appreciated. Thank.

+4
source share
1

:

  • models.json user Customer.

  • models/customer.js , models.json:

    var app = require('../app');
    var Customer = app.models.Customer;
    
    Customer.myfn = function(cb) {
      // etc.
      cb();
    };
    

, . .

strict :

{
  "Customer": {
    "options": {
      "base": "User",
      "strict": true
    },
    "properties": {
      // define properties (schema)
    }
  }
}

. .

-, . customer.js LoopBack, models.json..

:

var app = require('../app');

var Customer = module.exports = loopback.createModel(
  'Customer',
  {
    name: 'string',
    // and all other more properties
  },
  {
    base: 'User',
    strict: true
  }
);

app.model(Customer);

, app.boot models.json. REST : GET /customers, POST /customers/login, POST /customers/logout ..

, , , , "".

+4

Source: https://habr.com/ru/post/1546720/


All Articles