Created
May 24, 2019 17:23
-
-
Save jamescrowley/4cf7f86b48275ad51ee232fdb9e34b3e to your computer and use it in GitHub Desktop.
Boxwise import data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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