()
| 1027 | } |
| 1028 | return users; |
| 1029 | } catch (err) { |
| 1030 | logger.error("Firebase fetch operation failed!"); |
| 1031 | return []; |
| 1032 | } |
| 1033 | }; |
| 1034 | |
| 1035 | const getNonNickNameSyncedUsers = async () => { |
| 1036 | try { |
| 1037 | const usersRef = await userModel |
| 1038 | .where("roles.archived", "==", false) |
| 1039 | .where("nickname_synced", "==", false) |
| 1040 | .where("discordId", "!=", null) |
| 1041 | .get(); |
| 1042 | const users = []; |
| 1043 | usersRef.forEach((user) => { |
| 1044 | const userData = user.data(); |
| 1045 | if (userData?.discordId) |
| 1046 | users.push({ |
| 1047 | ...userData, |
| 1048 | id: user.id, |
| 1049 | }); |
| 1050 | }); |
| 1051 | return users; |
| 1052 | } catch (err) { |
| 1053 | logger.error(`Error while fetching all users: ${err}`); |
| 1054 | throw err; |
| 1055 | } |
| 1056 | }; |
| 1057 | |
| 1058 | const updateUsernamesInBatch = async (usersData) => { |
| 1059 | const batch = firestore.batch(); |
| 1060 | const usersBatch = []; |
| 1061 | const summary = { |
| 1062 | totalUpdatedUsernames: 0, |
| 1063 | totalOperationsFailed: 0, |
| 1064 | failedUserDetails: [], |
| 1065 | }; |
| 1066 | |
| 1067 | usersData.forEach((user) => { |
| 1068 | const updateUserData = { ...user, username: user.username }; |
| 1069 | batch.update(userModel.doc(user.id), updateUserData); |
| 1070 | usersBatch.push(user.id); |
| 1071 | }); |
| 1072 | |
| 1073 | try { |
| 1074 | await batch.commit(); |
| 1075 | summary.totalUpdatedUsernames += usersData.length; |
| 1076 | usersBatch.forEach((id) => { |
| 1077 | userCache.invalidateUser(id); |
| 1078 | }); |
| 1079 | return { ...summary }; |
| 1080 | } catch (err) { |
| 1081 | logger.error("Firebase batch Operation Failed!"); |
| 1082 | summary.totalOperationsFailed += usersData.length; |
| 1083 | summary.failedUserDetails = [...usersBatch]; |
| 1084 | return { ...summary }; |
| 1085 | } |
| 1086 | }; |
nothing calls this directly
no test coverage detected