Skip to content

Commit

Permalink
fix import function
Browse files Browse the repository at this point in the history
  • Loading branch information
tandpfun committed Aug 24, 2024
1 parent c79c395 commit d6c299a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ exports.importUsers = functions.https.onCall(async (data, context) => {

// Write user domain data (only need to use notFound since domain data is already written for found)
await batchWrite(
Object.keys(notFound),
(batch, email) => batch.set(userDomainDoc(allUsers[email]), { domain }),
notFound.map(email => userDomainDoc(allUsers[email])),
(batch, ref) => batch.set(ref, { domain }),
firestore,
(error) => errors.push(error)
);
Expand Down
3 changes: 3 additions & 0 deletions src/redux/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ export function setOrderSchedule(data, dispatch, domain) {

export async function importUsers(data, dispatch, domain) {
dispatch(setLoading(true));

// Turns an array of user objects into an object with email as key
let userData = {};
for (let user of data) {
if (user.email) {
Expand All @@ -308,6 +310,7 @@ export async function importUsers(data, dispatch, domain) {
userData[user.email] = thisUser;
}
}

let { updated, created, errors } = await importUsersFunction(userData, domain);
console.log(`Successfully updated ${Object.keys(updated).length} users`);
console.log(`Successfully created ${Object.keys(created).length} users`);
Expand Down

0 comments on commit d6c299a

Please sign in to comment.