0.2.9 • Published 4 years ago

loopback-visible-properties-mixin v0.2.9

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

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

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

5 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.0.2

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago