loopbackjs

The best solution for control access to models in strongLoop

别来无恙 提交于 2020-02-29 06:11:54
问题 I'm new in StrongLoop. I have 2 models( CustomUser and Item ). I want any CustomUser has access to his Items . I don't want use default APIs exposed by StrongLoop because i don't want CustomUsers able to define filter with these APIs. I define my RemoteMethod that returns items based on a internal filter. My question: Should i check current user and return his related items or can i use ACL in StrongLoop for this matter? If the ACL is correct answer, where should i insert my RemoteMethod(

The best solution for control access to models in strongLoop

爷,独闯天下 提交于 2020-02-29 06:11:25
问题 I'm new in StrongLoop. I have 2 models( CustomUser and Item ). I want any CustomUser has access to his Items . I don't want use default APIs exposed by StrongLoop because i don't want CustomUsers able to define filter with these APIs. I define my RemoteMethod that returns items based on a internal filter. My question: Should i check current user and return his related items or can i use ACL in StrongLoop for this matter? If the ACL is correct answer, where should i insert my RemoteMethod(

How to set relation foreign key to be required

浪子不回头ぞ 提交于 2020-01-24 20:37:46
问题 I have two models. Company and Booking. In the relation part of model Company "bookings": { "type": "hasMany", "model": "Booking", "foreignKey": "companyId" } The issue is, it is possible to post a Booking without companyId which is not ok. From the explorer. Booking { bookingId (string, optional), name (string), location (string), companyId (string, optional) } 回答1: You actually can't enforce this particular validation out-of-the-box. Instead you have a couple different options: a) You can

Loopback Connector REST API

百般思念 提交于 2020-01-20 08:33:12
问题 How to create an external API on Loopback? I want to get the external API data and use it on my loopback application, and also pass the input from my loopback to external API and return result or response. 回答1: Loopback has the concept of non-database connectors, including a REST connector. From the docs: LoopBack supports a number of connectors to backend systems beyond databases. These types of connectors often implement specific methods depending on the underlying system. For example, the

what is the callback in loopback (datasource.(automigrate))

≯℡__Kan透↙ 提交于 2020-01-17 05:29:11
问题 Loopback datasource API offers automigrate function with an optional callback. I see in some examples that the callback gets one parameter (err), but no definition of that. What form does the callback parameter have? Are there other possible parameters? How is this with the other functions? 回答1: Callbacks are nothing but the function which you passing as a parameter to the other function Look at this example function printResult(err,result) { if(err) { console.log('something went wrong');

Strongloop : Compare old model with the new instance in operation hook 'before save'

泪湿孤枕 提交于 2020-01-16 18:33:34
问题 I implemented a "before save" operation hook in my code to compare the new instance about to be saved with the old one already in the database. For that, I compare the value given in the ctx.data with the one given by a query in the database. The problem is the returned values are always similar, as if the new instance has already been saved in the database. Have I totally missed the point of the "before save" hook, or is there a way to compare the two values ? module.exports = function(app)

How to access 'req' object in loopback from “access” hook?

白昼怎懂夜的黑 提交于 2020-01-16 09:04:58
问题 It seems operation hook "access" does not contains ctx.req object. What i am trying to achieve is that session data should be available in all the models. Session defined in middleware: "session": { "express-session": { "params": { "secret": "mysceret", "saveUninitialized": true, "resave": true } } } In User.js : req.session.user = userData; and to access session in Post model: Post.observe('access', function(ctx, next) { console.log('ctx.req : ' , ctx.req) // undefined ctx.query.filter = {

Redirection after the login succeeds or fails in loopback framework

℡╲_俬逩灬. 提交于 2020-01-15 12:16:11
问题 I have recently started with loopback framework and made a simple login functionality by creating a 'customer' model inheriting from base 'User' like this: CUSTOMER.JSON { "name": "customer", "base": "User", "idInjection": true, "properties": { "email":{ "type":"string", "required":false }, "username":{ "type":"string", "required":false } }, "validations": [], "relations": {}, "acls": [], "methods": [] } CUSTOMER.JS module.exports = function(customer){ } I then made a entry in model-config

loopback.io model, acl principalId, $owner

做~自己de王妃 提交于 2020-01-15 11:48:09
问题 I need to limit data access in a model only to the loopback user that created it. I saw this in the docs: http://loopback.io/doc/en/lb2/Model-definition-JSON-file.html#acls $owner - Owner of the object Does that mean the logged in user who created that object? When a model runs create, is loopback.io storing the user id of the current logged in user inside it's own ACL? Or will I need to do something like this, which is to create new properties on my model with relations to the user model:

Loopback push array

故事扮演 提交于 2020-01-14 06:51:11
问题 How would I go about making a custom remoteMethod that updates/pushes, not overrides , a property that is an array . So basically push data to an array property of a model. I can't find any clear examples of this in the documentation, except for an .add() helper method, but that requires an embedsOne or some other relation. But what if I have a single Model in my whole app and would just want to push some data to an id . So ending up with an endpoint like: POST /Thing/{id}/pushData And the