Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] import prof ta error #802

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/firebasefunctions/importProfessorsOrTAs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import firebase from 'firebase';
import { firestore } from '../firebase';
import { blockArray } from '../firehooks';

Expand Down Expand Up @@ -56,15 +57,23 @@ const importProfessorsOrTAs = async (
demotedSet: Set<string>;
}> => {
const missingSet = new Set<string>(emailListTotal);
// eslint-disable-next-line no-console
console.log("missingSet", missingSet);
const demotedSet = new Set<string>();
const batch = db.batch();
const updatedUsers: FireUser[] = [];
const courseChange: FireCourse = { ...course };

const emailBlocks = blockArray(emailListTotal, 10);
// eslint-disable-next-line no-console
console.log("emailBlocks", emailBlocks);

return Promise.all(emailBlocks.map(emailList => {
return db.collection('users').where('email', 'in', emailList).get().then(taUserDocuments => {
// eslint-disable-next-line no-console
console.log("number of docs in users that match query", taUserDocuments.size)
// eslint-disable-next-line no-console
console.log("taUserDocuments (docs in users that match query)", taUserDocuments)
// const updatedUsersThisBlock: FireUser[] = [];
// const userUpdatesThisBlock: Partial<FireUser>[] = [];
const updatesThisBlock: { user: FireUser; roleUpdate: Partial<FireUser> }[] = [];
Expand All @@ -78,10 +87,61 @@ const importProfessorsOrTAs = async (
})
});

// creating new FireUsers for the emails that weren't found and applying the updates
// eslint-disable-next-line max-len
const missingEmails = emailList.filter(email => !taUserDocuments.docs.some(doc => doc.data().email === email));
// eslint-disable-next-line no-console
console.log("missingEmails", missingEmails);
missingEmails.forEach(email => {
const authProvider = new firebase.auth.GoogleAuthProvider();
authProvider.addScope('email');
authProvider.addScope('profile');

// firebase.auth().signInWithPopup(authProvider)
// .then((result) => {
// const user = result.user;
// const newUser: FireUser = {
// email,
// roles: { [course.courseId]: role },
// courses: [course.courseId],
// userId: db.collection('users').doc().id,
// firstName: user?.displayName?.split(' ')[0] || '',
// lastName: user?.displayName?.split(' ')[1] || '',
// photoUrl: user?.photoURL || ''
// };
// updatesThisBlock.push({
// user: newUser,
// roleUpdate: newUser
// });
// })
// .catch((error): void => {
// // eslint-disable-next-line no-console
// console.log("user not found", error);
// });

const newUser: FireUser = {
email,
roles: { [course.courseId]: role },
courses: [course.courseId],
userId: db.collection('users').doc().id,
firstName: '',
lastName: '',
photoUrl: ''
};
updatesThisBlock.push({
user: newUser,
roleUpdate: newUser
});
// eslint-disable-next-line no-console
console.log("new user created", newUser);
});

return updatesThisBlock;
});

})).then(updatedBlocks => {
// eslint-disable-next-line no-console
console.log("reaching then")
const allUpdates: { user: FireUser; roleUpdate: Partial<FireUser> }[] = [];

updatedBlocks.forEach(updateBlock => {
Expand Down Expand Up @@ -175,6 +235,10 @@ export const importProfessorsOrTAsFromPrompt = (
const response = prompt(
`Please enter a comma-separated list of ${role === 'professor' ? role : 'TA'} emails:`
);

// eslint-disable-next-line no-console
console.log("response", response);

if (response != null) {
importProfessorsOrTAs(
course,
Expand Down
Loading