strongloop

How do I create getter and setter overrides?

﹥>﹥吖頭↗ 提交于 2019-11-29 10:59:09
I'd like to encrypt fields similar to this example with mongoose: https://gist.github.com/kljensen/7505729 The code in the above link maps a field to a custom decrypt() function for get and an encrypt() function for set . This causes the plain text value to be encrypted when saved, and decrypted when retrieved. How would I override getters and setters for a model property in Loopback? Raymond Feng You can set up setter and getter as follows: <Model>.setter['myProp'] = function(val) {}; See an example in LoopBack's common/models/user.js 来源: https://stackoverflow.com/questions/24223329/how-do-i

How to run multiple StrongLoop LoopBack apps on the same server?

╄→尐↘猪︶ㄣ 提交于 2019-11-29 10:47:27
问题 I'm currently running two StrongLoop LoopBack apps (Nodejs apps) on a single server with different ports. Both apps were created using slc lb project and slc lb model from the command line. Is it possible to run these apps on a single ports with different path and/or subdomain? If it is, how do I do that on a Linux machine? Example: http://api.server.com:3000/app1/ for first app. http://api.server.com:3000/app2/ for second app. thanks. 回答1: Since LoopBack applications are regular Express

Dynamic Properties or Aggregate Functions in Loopback Models

会有一股神秘感。 提交于 2019-11-29 09:17:41
问题 How would I go about using aggregate functions in Loopback models? If I have a model backed by a mysql database, could I have Model1 with a hasMany relation to Model2 (with a given numeric property), and have a property in Model1 that grabs the SUM of that field from Model2? { "Model1" : { "Relations" : { "model2s" : { "type": "hasMany", "model": "Model2", "foreignKey": "model1Id" } }, "Properties" : { "total" : { "type": "Number" [SUM of Model2 'amount' field] } } }, "Model2" : { "Relations"

Can I define a custom validation with options for Loopback?

会有一股神秘感。 提交于 2019-11-29 08:06:53
Is there a prescribed way to create a custom validator in loopback? As an example, assume that I want to create something like: Validatable.validatesRange('aProperty', {min: 0, max: 1000}) Please note that I am aware of: Validatable.validates(propertyName, validFn, options) The problem I have with validates() is that validFn does not have access to the options. So, I'm forced to hard code this logic; and create a custom method for every property that needs this type of validation. This is undesirable. Similarly, I am familiar with: Model.observes('before save', hookFn) Unfortunately, I see no

Destroy a model in loopback.io

血红的双手。 提交于 2019-11-29 04:54:19
问题 How can I delete a model in strongloop's loopback.io? I have seen somewhere command called persistedModel.destroy() but when I exectute slc persistedModel.destroy() I get command not found error. 回答1: Delete /common/models/your-model.js and /common/models/your-model.json , then delete the lines referencing your model in /server/model-config.json . 来源: https://stackoverflow.com/questions/28512991/destroy-a-model-in-loopback-io

Execute raw query on MySQL Loopback Connector

六眼飞鱼酱① 提交于 2019-11-29 02:57:27
问题 How is it possible to execute raw query and expose results through REST API with strongloop? I've read something about using hooks and dataSource.connector.query() but I cannot find any working examples. 回答1: Here is a basic example. If you have a Product model (/common/models/product.json), extend the model by adding a /common/models/product.js file: module.exports = function(Product) { Product.byCategory = function (category, cb) { var ds = Product.dataSource; var sql = "SELECT * FROM

Migrating built-in models to Databases

雨燕双飞 提交于 2019-11-28 11:15:25
How to move built-in models like User, Roles, User-Role-Mapping etc... to the database we've created instead of the default datasource:db? The built-in models are not listing in Arc. I've tried creating a new model which inherits these base model. But, data is not saved into the new model. Please advice...I've been sitting on it for a couple of weeks. Thanks Default "db" datasource is placed in memory. That is why your data are not persisted after you restart application. You have to install appropriate database connector and then you have to add datasource for your database inside server

How to Modify the StrongLoop's LoopBack Explorer CSS

拈花ヽ惹草 提交于 2019-11-28 09:53:41
We're using Strongloop's LoopBack for our REST APIs and would like to modify the CSS for the LoopBack Explorer. However, it's not clear which CSS files are being used (LoopBack vs Swagger) and where they're located. I was not able to find specific documentation for this. You can provide your own version of Swagger UI files via options.uiDirs . Edit your server/server.js and add this config option to the explorer: app.use(explorer(app, { uiDirs: path.resolve(__dirname, 'explorer') })); Copy the directory node_modules/loopback-explorer/public/css to server/explorer/css Customize the copied CSS

How do I create getter and setter overrides?

旧街凉风 提交于 2019-11-28 04:36:06
问题 I'd like to encrypt fields similar to this example with mongoose: https://gist.github.com/kljensen/7505729 The code in the above link maps a field to a custom decrypt() function for get and an encrypt() function for set . This causes the plain text value to be encrypted when saved, and decrypted when retrieved. How would I override getters and setters for a model property in Loopback? 回答1: You can set up setter and getter as follows: <Model>.setter['myProp'] = function(val) {}; See an example

Can I define a custom validation with options for Loopback?

半城伤御伤魂 提交于 2019-11-28 01:32:16
问题 Is there a prescribed way to create a custom validator in loopback? As an example, assume that I want to create something like: Validatable.validatesRange('aProperty', {min: 0, max: 1000}) Please note that I am aware of: Validatable.validates(propertyName, validFn, options) The problem I have with validates() is that validFn does not have access to the options. So, I'm forced to hard code this logic; and create a custom method for every property that needs this type of validation. This is