| 924 | |
| 925 | // Commit all batches concurrently |
| 926 | await Promise.all(batches.map((batch) => batch.commit())); |
| 927 | } catch (err) { |
| 928 | logger.error(`Error while deleting tokens field: ${err}`); |
| 929 | throw err; |
| 930 | } |
| 931 | }; |
| 932 | |
| 933 | const getUsersByRole = async (role) => { |
| 934 | try { |
| 935 | const usersRef = await userModel.where(`roles.${role}`, "==", true).get(); |
| 936 | const users = []; |
| 937 | usersRef.docs.forEach((user) => { |
| 938 | const userData = user.data(); |
| 939 | users.push({ |
| 940 | ...userData, |
| 941 | id: user.id, |
| 942 | }); |
| 943 | }); |
| 944 | return users; |
| 945 | } catch (err) { |
| 946 | logger.error(`Fetching users with role: ${role} exitted with an error: ${err}`); |