Skip to content

Instantly share code, notes, and snippets.

@jamescrowley
Created May 24, 2019 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamescrowley/4cf7f86b48275ad51ee232fdb9e34b3e to your computer and use it in GitHub Desktop.
Save jamescrowley/4cf7f86b48275ad51ee232fdb9e34b3e to your computer and use it in GitHub Desktop.
Boxwise import data
admin
.auth()
.listUsers()
.then(listUsersResult => {
const selectedUser = listUsersResult.users.filter(
usr => usr.email.toLocaleLowerCase() === testUserEmail
);
if (selectedUser.length > 0) {
return Promise.resolve();
}
const testOrg = {
name: testOrgName,
createdAt: Date()
};
return admin
.firestore()
.collection("organizations")
.add(testOrg);
})
.then(createdTestOrg => {
// eslint-disable-next-line no-console
console.log("Successfully created new org:", createdTestOrg.id);
return admin
.auth()
.createUser({
email: testUserEmail,
password: testUserPwd,
displayName: testUserName,
emailVerified: false
})
.then(userRecord => ({ userRecord, createdTestOrg }));
},
error => {
// eslint-disable-next-line no-console
console.log("Error creating test organization:", error);
process.exit(1);
})
.then(({userRecord,createdTestOrg}) => {
// eslint-disable-next-line no-console
console.log("Successfully created new user:", userRecord.uid);
const testUser = {
name: userRecord.displayName,
organization: admin
.firestore()
.doc(`organizations/${createdTestOrg.id}`)
};
return admin
.firestore()
.collection("profiles")
.doc(userRecord.uid)
.set(testUser);
},
error => {
// eslint-disable-next-line no-console
console.log("Error creating test user:", error);
process.exit(1);
})
.then(() => {
// eslint-disable-next-line no-console
console.log("Successfully created new user profile");
process.exit(0);
},
error => {
// eslint-disable-next-line no-console
console.log("Error creating test user profile:", error);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment