I am working on an app using loopback . Need help and suggestions on models relationship and role.
- Multiple organisations
- An organisation have multiple admin and multiple user.
I'm using relation like
- Organisation hasMany. User
- User belongs to organisation
- Created a admin role.Don't want use $owner because in future may owner is not available.
- created two models users and organization
How can I list all user belongs to a organisation. How to differentiate b/w Admins/Users of different org.
Do I have to create custom filter for that?
//user.json
"properties": {
"email": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {
"organization": {
"type": "belongsTo",
"model": "Organization",
"foreignKey": "orgUserId"
},
"templates": {
"type": "hasMany",
"model": "Template",
"through": "Share"
}
}
}
//organization.json
"properties": {
"name": {
"type": "string"
}
},
"validations": [],
"relations": {
"users": {
"type": "hasMany",
"model": "user",
"foreignKey": "orgUserId",
"properties" :{
"name": "realm"
}
},
"templates": {
"type": "hasMany",
"model": "Template",
"through": "Share"
}
},
Please help. Thanks