loopback-visible-properties-mixin

0.2.9 • Public • Published

loopback-visible-properties-mixin

npm version Build Status Coverage Status

Loopback mixin hidden all models properties and allow setup what should be visibles.

Installation

npm install loopback-visible-properties-mixin --save

Usage

Add the mixins property to your server/model-config.json:

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "../node_modules/loopback-visible-properties-mixin",
      "../common/mixins"
    ]
  }
}

Add mixin params in in model definition. Example:

{
  "name": "Person",
  "properties": {
    "firstName": "string",
    "lastName": "string",
    "email": "string",
  },
  "relaions": {
    "siblings": {
      "type": "referencesMany",
      "model": "Person",
      "foreignKey": "siblingsIds"
    },
    "mother": {
      "type": "belongsTo",
      "model": "Person",
      "foreignKey": ""
    },
    "father": {
      "type": "belongsTo",
      "model": "Person",
      "foreignKey": ""
    },
    "couple": {
      "type": "belongsTo",
      "model": "Person",
      "foreignKey": ""
    },
    "children": {
      "type": "hasMany",
      "model": "Person",
      foreignKey: "motherId"
    },
  },
  "mixins": {
    "VisibleProperties": {
      "fields": {
        "firstName":   true,
        "lastName":    true,
        "email":       false,
        "mother":      true,
        "motherId":    false,
        "father":      true,
        "fatherId":    false,
        "siblings":    true,
        "siblingsIds": false,
        "children":    true
      }
    }
  }
}

You can setup this mixin with a array of visible properties too. Example:

{
  "name": "Person",
  ...
  "mixins": {
    "VisibleProperties": {
      "fields": [
        "firstName",
        "lastName",
        "mother",
        "father",
        "siblings",
        "children",
      ]
    }
  }
}

In the above definitions, the attributes id, couple and coupleId will not be visible in remote responses because they were ignored and email, motherId, fatherId and siblingsIds will not be visible because they were set false.

Troubles

If you have any kind of trouble with it, just let me now by raising an issue on the GitHub issue tracker here:

https://github.com/arondn2/loopback-visible-properties-mixin/issues

Also, you can report the orthographic errors in the READMEs files or comments. Sorry for that, I do not speak English.

Tests

npm test or npm run cover

Package Sidebar

Install

npm i loopback-visible-properties-mixin

Weekly Downloads

10

Version

0.2.9

License

MIT

Unpacked Size

12.7 kB

Total Files

8

Last publish

Collaborators

  • arondn2