I have two entities that are connected with a ManyToMany relationship:
// Branch entity
@ManyToMany(
(type) => User,
(e) => e.branches
)
users: User[];
// User entity
@ManyToMany(
(type) => Branch,
(e) => e.users,
{ eager: true,
cascade: false }
)
@JoinTable()
branches: Branch[];
@IsEnum(Role)
@Column('text', { default: Role.Client })
role: Role;
I am looking to find branches where the users list does not contain a user with the role 'client'.
This functionality is needed for the following scenario:
[
Branch {
id: '98007770-c924-43cd-988c-774492e1e759',
name: 'poslovnica1',
users: [ {role:'client'},{role:'superAdmin'} ]
},
Branch {
id: '787007770-c924-43cd-988c-774492e1e759',
name: 'poslovnica13',
users: [ {role:'client'},{role:'superAdmin'} ]
},
Branch {
id: '36f5b1ad-6553-4b2f-936b-33fb4ca8e73e',
name: 'poslovnica2',
users: [ {role:'superAdmin' }]
}
]
After filtering, the desired result is to retrieve all branches that do not have a user with the role 'client' or 'superAdmin':
[
Branch {
id: '36f5b1ad-6553-4b2f-936b-33fb4ca8e73e',
name: 'poslovnica2',
users: [ {role:'superAdmin'} ]
}
]