loopbackjs

Loopback validation on Properties who's types are other Models

心已入冬 提交于 2019-12-11 01:25:01
问题 I have two Models defined; Location and Address, defined as follows: "address": { "properties": { "address1": { "type": "string", "required": true } }, "public": true, "dataSource": "db", "plural": "addresses" }, "location": { "properties": { "title": { "type": "string" }, "address":{ "type": "address", "required": true } }, "public": true, "dataSource": "db", "plural": "locations" } When I Create an object based on the address Model via the API Explorer, the required constraint on address1

Dynamic Models in Loopback

拈花ヽ惹草 提交于 2019-12-11 00:56:08
问题 How to create a dynamic models in loopback, instead of using the command "lb model" for all models. For ex: If I want to create 30 models with almost same properties, will be in trouble of creating all the 30 models and those corresponding properties again and again. Is it possible to create the model and iterate it to another model using loopback. Kindly share your answers. 回答1: Well, I'm still new to this but I think, you can easily create any number of dynamic models programmatically. For

How can I run loopback application on port 80

房东的猫 提交于 2019-12-11 00:25:03
问题 I'm using loopback.io which base on expressjs and I tried to add port as the first parameter of app.listen like this: // server.js app.start = function() { // start the web server return app.listen(80, function() { app.emit('started'); console.log('Web server listening at: %s', app.get('url')); }); }; But it doesn't work. I have been searching for this for awhile but I haven't found the solution yet. 回答1: Change the port property in server/config.json . See https://github.com/strongloop

How can I filter REST calls results based on Roles and current user context in Loopback (server side)

眉间皱痕 提交于 2019-12-10 23:16:41
问题 Given the following: There are 3 models: Company Employee (derived from User) Position Company is linked to Employee through Position (has many, has many) There are 2 Roles: admin user I would like to configure my REST api as follow: When an admin is logged, can access all REST functions. "accessType": "*", "principalType": "ROLE", "principalId": "admin", "permission": "ALLOW" When a user is logged: GET /companies : Only return the companies in which the current user has a position. GET

How to write remote hook for a method with parameter and relation

别说谁变了你拦得住时间么 提交于 2019-12-10 23:09:08
问题 I went through the remote hook documentation, I can successfully create remote hooks for methods without extra parameters, like login , which is: customer.afterRemote('login', function(ctx, modelInstance, next) { if (ctx.result) { ... next(); } else{ next(); } }); Now, How to write a remote hook for a method say : GET /customers/{id} POST /customers/{id} or while posting related objects like POST /customers/{id}/contacts GET /customers/{id}/contacts I know doing the following with POST

Loopback: Atomic read and update

送分小仙女□ 提交于 2019-12-10 23:08:41
问题 is there a way to implement something like this in loopback? LOCK READ INCREMENT UNLOCK I would like to keep counters as database values, each key is a counter (or a setting), and they shouldn't accessed my multiple requests at the same time. Also this should work for local requests too (no remoteHooks) Thanks 回答1: If you are using the mongoDB connector, this is supported by extended operators. MyModel.updateAll( { id: 123' }, { '$inc': { myproperty: 1 }}, // increment myproperty by 1 {

NodeJS How to import JS file into TypeScript

眉间皱痕 提交于 2019-12-10 22:51:30
问题 I'm new with TypeScript. I'm currently learning NodeJS Loopback 4 framework which use Typescript language. And my question is how to import some function, class which has been exported in JS file into my TS file. After search several way but it still doesn't work with me. Here's example: // /src/index.ts import {plus} from './lib/test'; console.log(plus(1,2)); // /src/lib/test.js export function plus(x, y) { return x + y; } I also try using definition typescript like this // /src/lib/test.d

How to override the default password hashing method and validation method of loopback?

青春壹個敷衍的年華 提交于 2019-12-10 18:23:51
问题 I am very new to Loopback and i want to override the default hashing of password method of loopback to the one that is currently used in my backend so that i can sync this application with that database . i read this link https://groups.google.com/forum/#!topic/loopbackjs/ROv5nQAcNfM but i am not able to understand how to override the password and validation? 回答1: You can override User.hashPassword to implement your own hashing method. Let's say you have a model Customer which has User as

Extend built-in User model to support more properties and behaviors in loopback

本秂侑毒 提交于 2019-12-10 17:50:01
问题 I want a model to represent a profile in my loopback app. But, the built-in User model found in loopback only have the following properties username password realm emailVerified What is the best way to extend the built-in User model in order to insert more properties like phone number , profile picture , and the likes ? 回答1: It was better if you have added your code for better answer according to your question but you can check this site which talks about customizing the built-in user model

Loopback models in ES6

最后都变了- 提交于 2019-12-10 16:47:40
问题 I'm new to loopback.js. I want to use the ES6 syntax for classes. How to achieve this using the way that the models are defined by loopback? module.exports = function(MyModel) { MyModel.on('dataSourceAttached', function(obj){ var find = MyModel.find; MyModel.find = function(filter, cb) { return find.apply(this, arguments); }; }); }; 回答1: Some ideas by https://github.com/NextFaze/Loopback-Style-Guide#custom-model-methods I create a bootstraping class in ES6 for managment models. I create 2