loopbackjs

Save multiple models in loopback

为君一笑 提交于 2019-12-01 12:45:31
问题 I'm doing research on loopback and was wondering if it's possible to save to multiple models from one request. Say.. an Post has many Tags with many Images. A user form would have the following: Post Title Post Description Tag Names (A multi field. E.g.: ['Sci-Fi', 'Fiction', 'BestSeller'] Image File (Hoping to process the file uploaded to AWS, maybe with skipper-s3?) How would I be able to persist on multiple models like this? Is this something you do with a hook? 回答1: You can create

Social Logins authentication through loopback-passport

删除回忆录丶 提交于 2019-12-01 12:35:28
I am starting to gain grounds with loopback api . Currently I am trying to integrate authentication through social login for my app. I have found three pages that indicate how to accommplish this but they all show this a bit differently and unclear: github-loopback-component-passport & npmjs-loopback-component-passport & github-loopback-component-passport-example . I am bit confused as to what is the most up to date process. Can anyone shed some light in how to best integrate social login with loopback? Also, how to test it for routes that may require access tokens? Here is the Github Repo of

Make a join query in loopback.io

走远了吗. 提交于 2019-12-01 09:27:55
I am trying to build a simple application using loopback.io as process of my learning. I have set up the project, created models and apis are working fine. Now I am trying to create a custom api which can get the data from two different models by making a join query. So i have a two models stories : id, title, noteId notes : id , desc i have stories.js file as module.exports = function(Stories) { Stories.list = function(cb) { // make a join query }; Stories.remoteMethod( 'list', { http: { path: '/list', verb: 'get' }, returns: { arg: 'list', type: 'array' } } ); }; In general i will make a

auto-increment using loopback.js and MongoDB

泄露秘密 提交于 2019-12-01 08:37:01
i want to increase mongodb document number automatically using loopback. I made function in mongo function getNextSequence(name) { var ret = db.counters.findAndModify( { query: { _id: name }, update: { $inc: { seq: 1 } }, new: true } ); return ret.seq; } db.tweet.insert( { "_id" : getNextSequence("userid"), "content": "test", "date": "1", "ownerUsername": "1", "ownerId": "1" } ) It is working in mongo shell. However when I insert using loopback.js browser ( http://localhost:3000/explorer/ ), It is not working. 400 error(SytaxError) code is showing. I can not use mongo function in loopback rest

JS Object strange behaviour when trying access Loopback related model query

人盡茶涼 提交于 2019-12-01 07:31:27
I am working with the Loopback Framework, doing a web project. But I think that the question that I am exposing here has less to do with this, but with general Javascript / Node.JS knowledge. At one part of the code, I am doing: roleMapping.find({ where: { principalType: 'USER', principalId: context.principals[0].id }, include: 'role' }, function(err, roles){ console.log(roles[0]); for (var i in roles) { if (roles[i].role.name === 'teamLeader' && roles[i].groupId === context.modelId) { cb(null,true); }else { cb(null,false); } } }); Ok with this, but it fails when trying to compare roles[i]

auto-increment using loopback.js and MongoDB

ε祈祈猫儿з 提交于 2019-12-01 07:06:23
问题 i want to increase mongodb document number automatically using loopback. I made function in mongo function getNextSequence(name) { var ret = db.counters.findAndModify( { query: { _id: name }, update: { $inc: { seq: 1 } }, new: true } ); return ret.seq; } db.tweet.insert( { "_id" : getNextSequence("userid"), "content": "test", "date": "1", "ownerUsername": "1", "ownerId": "1" } ) It is working in mongo shell. However when I insert using loopback.js browser (http://localhost:3000/explorer/), It

JS Object strange behaviour when trying access Loopback related model query

给你一囗甜甜゛ 提交于 2019-12-01 03:51:36
问题 I am working with the Loopback Framework, doing a web project. But I think that the question that I am exposing here has less to do with this, but with general Javascript / Node.JS knowledge. At one part of the code, I am doing: roleMapping.find({ where: { principalType: 'USER', principalId: context.principals[0].id }, include: 'role' }, function(err, roles){ console.log(roles[0]); for (var i in roles) { if (roles[i].role.name === 'teamLeader' && roles[i].groupId === context.modelId) { cb

How to configure two different datasource for a model in Strongloop Loopback framework?

*爱你&永不变心* 提交于 2019-12-01 02:20:42
问题 Our MySQL database are set up with Write clusters and Read clusters, is there a way to set up Strongloop Loopback Model (e.g. User) to Write to MySQL Host A and Read from MySQL Host B? 回答1: Try to use attachTo() if you want to change datasource for a single model. For example app.models.YourModel.attachTo(app.dataSources.readDS); readData(); ... app.models.YourModel.attachTo(app.dataSources.writeDS); writeData(); You will have to define readDS and writeDS datasources in your datasources.json

Level 2 (related model) scope over REST - strongloop api

十年热恋 提交于 2019-12-01 00:41:41
I found in the documentation that scopes enable you to specify commonly-used queries that you can reference as method calls on a model. Below i have a categories model. I am trying to create scopes that applies to the relation with model games . Unfortunately the below does nothing. How can I get scopes to apply to relation as shown below? GET /Categories/{id}/games - This gets all games common/models/category.json "relations": { "categories": { "type": "hasMany", "model": "game", "foreignKey": "" } }, /common/models/game.json "scopes": { "mature": {"where": {"mature": true}} }, "validations":

Using custom Loopback user model with loopback-component-passport

无人久伴 提交于 2019-12-01 00:37:46
I'm trying to use a extended loopback user model together with the loopback-component-passport for facebook login. The login itself is working but i can't get it to use my custom user model instead of the builtin "Users". steps i took: - create custom user model with slc loopback:model extending "User" { "name": "myuser", "plural": "myusers", "base": "User", "idInjection": true, "options": { "validateUpsert": true }, "properties": { "mytestproperty": { "type": "string", "default": "myteststring" } }, "validations": [], "relations": {}, "acls": [], "methods": {} } - Setup passport component