loopbackjs

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

Modify image obtained from loopback-component-storage

时光毁灭记忆、已成空白 提交于 2019-11-27 13:56:30
问题 I am using loopback for storing Image to the server . I want to modify the file name of the file before getting saved to the server. Also I want to convert it to another thumbnail form before getting saved. Here is how I am doing. At client side Upload.upload( { url: '/api/containers/container_name/upload', file: file, fileName: "demoImage.jpg", //Additional data with file params:{ orderId: 1, customerId: 1 } }); At Server Side I am receiving the query "params" but not getting the "File Name"

Migrating built-in models to Databases

耗尽温柔 提交于 2019-11-27 06:10: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 回答1: Default "db" datasource is placed in memory. That is why your data are not persisted after you restart application. You have to

How to store files with meta data in LoopBack?

北城以北 提交于 2019-11-26 21:30:33
What I want to do: Have an html form, with a file input inside. When a file is chosen, the file input should upload the file, and get a file id, so when the form is submitted, the file id is posted with the form and written in the database. Shorter version: I want to store meta data (id for example) with my files. Sounds simple, yet I struggle to do that in LoopBack. There has been a couple conversations ( 1 , 2 ) about this topic, and neither seemed to lead to a solution, so I thought this might be a good place to find one once and for all. The simplest solution would be to use model

How can i return status inside the promise?

天涯浪子 提交于 2019-11-26 16:49:57
I started to learning promise with loopback and jsforce, and couldn't handle this problem; I couldn't return status var inside promise to cb() function. Basically i want to connect salesforce and get data via JSforce and write it to db via loopback. Then want to return created/updated/error records to client after remote mothed called. I'm developing with Loopback via using Node.JS & Express.js I'm using JSforce library to connect salesforce How can I fix that? Here is my code: module.exports = function(Contact) { var jsforce = require('jsforce'); var async = require("async"); var lr = require

How to store files with meta data in LoopBack?

纵饮孤独 提交于 2019-11-26 07:59:02
问题 What I want to do: Have an html form, with a file input inside. When a file is chosen, the file input should upload the file, and get a file id, so when the form is submitted, the file id is posted with the form and written in the database. Shorter version: I want to store meta data (id for example) with my files. Sounds simple, yet I struggle to do that in LoopBack. There has been a couple conversations ( 1, 2 ) about this topic, and neither seemed to lead to a solution, so I thought this