1.0.5 • Published 5 years ago
loopback-company-context-mixin v1.0.5
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",
}
},
}