loopback-company-context-mixin

1.0.5 • Public • Published

Company context

This module is for the loopback framework. It add user's companyId to every read request's query.

NOTE! Adding companyId to request require active accessToken. It won't work with unauthorized routes. And you need to add options to request

{
  "accepts": [
    {
      "arg": "options",
      "type": "object",
      "http": "optionsFromRequest"
    }
  ]
}

INSTALL

  npm i loopback-company-context-mixin --S

SERVER CONFIG

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-company-context-mixin",
      "../common/mixins"
    ]
  }
}

MODEL CONFIG

To use with your Models add the mixins attribute to the definition object of your model config.

  {
    "name": "Widget",
    "properties": {
      "name": {
        "type": "string",
      }
    },
    "mixins": {
      "CompanyContext" : true
    }
  }

MODEL OPTIONS

You can use ignore option, if you want that mixin skip some of remote methods.

  {
    "name": "Member",
    "mixins": {
      "CompanyContext" : {
        "ignore": [
          "register",
          "login",
          "logout",
          "resetPassword",
          "invitationRequest"
        ]
      }
    },
    "properties": {
      "name": {
        "type": "string",
      }
    },
  }

Readme

Keywords

none

Package Sidebar

Install

npm i loopback-company-context-mixin

Weekly Downloads

3

Version

1.0.5

License

ISC

Unpacked Size

3.63 kB

Total Files

5

Last publish

Collaborators

  • likethearms