strongloop

Loopback: near filter on object sub-field

只谈情不闲聊 提交于 2019-12-11 04:15:55
问题 I have a Model like this: { name: 'My Favorite Shop', address:{ location: [12.534 /* longitude */ ,41.9221/* latitude */] } } Documents are stored in a mongodb database, and thus I'd like to query them like: //assuming shops to be the name of the containing model app.models.shops.find({ where: { 'address.location': {lat: 13, lng: 40} } }, callback); Problem is this query would not retrieve any result. I guess it's because of the nature of location field, which is nested into address , but I

Loopback API include filters not working as expected

可紊 提交于 2019-12-11 03:55:48
问题 I have used different models to simplify what I am trying to achieve and to remove clutter, although the theory should be the same as my actual project. Use the following assumptions: A system can only have one type of speaker and one type of amp. Say I have the following models: *** System *** - id - name - speakerId - ampId *** Speaker *** - id - name *** Amp *** - id - name I have added the following to my System.json model file (which i think is correct): "relations": { "speakers": {

Loopback accessToken not persisted to database

橙三吉。 提交于 2019-12-11 03:47:10
问题 The access tokens created are not being persisted to the postgresql database. I created extended users and access_tokens models using the strongloop controller interface using the User and AccessToken models as parents. On login the user is successfully queried from the database, login is successful, and the access token is created. However the access token is not persisted in the database and so essentially the login fails. Inside my model_config.json I have the following entries: "access

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 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

Customizing User built-in Model validation

女生的网名这么多〃 提交于 2019-12-10 11:54:20
问题 I'm looking for a way to customize the validation for the built-in User Model. The objective is to be allow users to register an account with the same e-mail but different username. I've tried to override the Setup Method for the User Model to prevent the validation of the uniqueness of the email property, but unfortunately that was a no go. As for hooks, I've couldn't find any to fulfill my needs. For reference, the validation occurs in 'loopback/common/models/user.js:556': if (!(UserModel

LoopBack: How to Dynamically Create Custom REST Endpoints In Code (On The Fly)

你离开我真会死。 提交于 2019-12-10 10:55:18
问题 We are using the LoopBack REST framework to expose our database (and business logic). We need to allow our customers to create custom tables in the database (single and multi-tenant) which can be accessed via a REST endpoint. All customers need to use the same common (production) REST endpoints which will be on exposed on multiple servers. However, custom tables and associated REST endpoints need to be accessible to only the customers that created them. Which means we cannot write the model

How to set up the ACL to allow everyone list all the Users from the REST API

妖精的绣舞 提交于 2019-12-10 01:50:07
问题 Im trying to list all the Users in my loopback 2.0 app using the REST API and I'm getting the following error: { "error": { "name": "Error", "status": 401, "message": "Authorization Required", "statusCode": 401, "stack": "...." } } I manually added the ACL to the model-config.json file: "User": { "dataSource": "db", "acls": [ { "principalType": "ROLE", "principalId": "$everyone", "permission": "ALLOW", "accessType": "*" } ] }, Since that failed, I created a model based on the User built-in

Diacritic Case-Insensitive search Loopback

China☆狼群 提交于 2019-12-09 09:37:44
问题 Is there any way to query results on Loopback+MongoDB with Diacritic-Case-Insensitive options? For example, If I want to search for the query olimpic , and the database contains words like: Olímpic olimpic Olimpic Then, all of the above should be returned as results. I have tried with multiple queries listed below and other combinations, but nothing has worked so far. {"where":{"name.text":{"like":"olimpic","options":"i"}}} {"where":{"name.text":{"like":"/^olimpic$/i","options":"i"}}} {"where