Skip to content
This repository was archived by the owner on Jul 11, 2019. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1ee2091

Browse files
committedAug 22, 2018
Add method to retrieve assoc. users with their roles
1 parent 737e9ff commit 1ee2091

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed
 

‎src/firebase/firestore/users.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export async function getAllUserSnaps() {
3838
*
3939
* @param {firestore.DocumentReference} associationRef Self descriptive
4040
*/
41-
export async function getAllAssociationUsersSnaps(associationRef) {
41+
export async function getAllAssociationUsersDocs(associationRef) {
4242
const rolesQuery = await getAssociationRolesRef(associationRef.id).get();
4343
const usersDocs = [];
4444
rolesQuery.forEach(async roleDoc => {
@@ -54,6 +54,33 @@ export async function getAllAssociationUsersSnaps(associationRef) {
5454
return usersDocs;
5555
}
5656

57+
/**
58+
* Fetches all users that belongs to the provided association
59+
*
60+
* @param {firestore.DocumentReference} associationRef Self descriptive
61+
*/
62+
export async function getAllAssociationUsersDocsWithRoles(associationRef) {
63+
const rolesQuery = await getAssociationRolesRef(associationRef.id).get();
64+
const usersWithRoles = [];
65+
66+
rolesQuery.forEach(async roleDoc => {
67+
const usersQuery = await usersRef()
68+
.where("associations", "array-contains", {
69+
associationRef,
70+
roleRef: roleDoc.ref
71+
})
72+
.get();
73+
usersQuery.forEach(userDoc =>
74+
usersWithRoles.push({
75+
userDoc: userDoc,
76+
roleDoc
77+
})
78+
);
79+
});
80+
81+
return usersWithRoles;
82+
}
83+
5784
/**
5885
* Fetches a user document
5986
*

0 commit comments

Comments
 (0)
This repository has been archived.