Moqui:Can we create parent and child relation between two users - moqui

I just want to create one organization(Pharmacy) and under that organization need a different kinds of user like admin user, inventory user, billing user......etc

In your case, there are two dimensions of data control
by userGroup
by organization
So the solution would be:
create organization ['Phrmaacy1', 'Phrmaacy2']
create person ['Admin1', 'Admin2', 'Inventory1', 'Inventory2'], and userAccount for these persons
create userGroup ['Admin', 'Inventory']
create partyRelationship ['Admin1', 'Inventory1'] as member of ['Phrmaacy1'], and ['Admin2', 'Inventory2'] as member of ['Phrmaacy2']
create userGroupMember to put userAccount of person ['Admin1', 'Admin2'] in userGroup ['Admin'], userAccount of person ['inventory1', 'inventory2'] in userGroup ['Inventory']
Use both organization and userGroup the user belong to to filter out data, and use userGroup (userGroupPermissions, artifactAuthz) to control permission the user is allowed to perform.

Related

API paths for Many to Many relationship

I have the following entities on an Api:
Organization > OrganizationId (PK), Name, ...
User > UserId (PK), Name, ...
OrganizationEnrolment > (OrganizationId, UserId) (PK), EnromentTypeId
So OrganizationEnrolment has the enrolments of users in organisations.
An user can only have one enrolment per Organization so the PK (OrganizationId, UserId).
I have a few API endpoints like:
GET Organization = GET organizations/{organizationId}
Update Organization = PUT organizations/{organizationId}
Create User = POST users
Delete User = DELETE users/{userId}
The question is:
What should be the API urls to Create, Delete and Update an Organization Enrolment?
I am struggling with it ...
Get Organization Employees: GET organizations/{organizationId}/employees
Attach Employees to Organization: PUT organizations/{organizationId}/employees
Remove Employees from Organization without deleting Employees: DELETE organizations/{organizationId}/employees

SQL: Employee and Customer are Users, But not all Employees are Users

I'm trying to model a database for a rest server which is accessed via mobile app and web clients. Both Employees and Customers are users of the system. I have previously used composition rather than inheritance to design the database. I have used the design from this answer as such.
User (user_id, fullname, email, username)
Role (role_id, description)
UserRole (user_role_id, user_id,role_id, date_from, date_thru)
Customer (user_id, ...)
Employee (user_id, ...)
The problem is that to have an employee you need to have a user but not all employees are users i.e. I'm currently told to include drivers who are employees but not users of th system. So how can I create such a relationship?
You can have another composition level saying called "Person". So employees and customers are persons and persons could be users.
For the employees who are not user, you can have user_id equal to NULL.

SQL Select aspnet_UsersInRoles - multiple roles

Suppose I had a customer table and each customer can belong to several roles. I'm trying to populate an old gridview of customers but if a customer is a member of a role like "external" then I do not want that customer to appear...BUT that particular customer is also a member of a role called "editor" thus the customer is still included.
In other words, how can I, in SQL, say...if that customer is in that role, don't include him at all even if he is a member of other roles.

Handling table with multiple child entities with Discriminators

I have a user table with different types of users. The type of the user is determined by user_type column in user table. I have a company table which has one to many relationship with User. I have different classes for different users like Guest, Admin (children of User class) each with a discriminator value.
My Company class has:
private Set<Guest> guests;
private Set<Admin> admins;
How can I write a single hql query to join company and user table to populate guest users into guest set and admin users into admin set?
Like select company left outer join fetch company.guests left outer join admin.guests. I cannot find a way to include user_type while making these joins.

Database schema: how to implement feedback from users?

I have table 'users'. Users can have roles - 'client' and 'employee'. Clients can give employees feedback (rating). I am not sure, how to implement it correctly, since clients and employees are one entity in schema (users).
I thought about something like this:
So, if a user has role 'client' then he will have feedback through 'given_feedback', and if 'employee', then through 'received_feedback'? Is it appropriate way to do it?
It is alike to this question: Database Design - Linking two users though in my case it is important to know who gave the feedback and who received it.
I would do something like this:
users
id
first_name
last_name
email
role_id
etc..
feedback_users
id
user_id
given_feedback - a value that tells if it's given (1) or recieved feedback (0))
feedback_text
roles
id
name
(two rows with client and employee)
Relations between above tables:
users.id - feedback_users.id (1 to many)
users.role_id - roles.id (many to 1) //given that a user can only have one role