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

WIP: Refactor of registerUsers to use batched approach #619

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
86 changes: 48 additions & 38 deletions src/pages/RegisterStudents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,10 @@ async function submitStudents() {
}
// Begin submit process
const totalUsers = submitObject.length;
const chunkedSubmitObject = _chunk(submitObject, 10);
const chunkedSubmitObject = _chunk(submitObject, 1000);
for (const chunk of chunkedSubmitObject) {
const students = [];
// TODO: Chunk into groups of 1000 and use importUsers (from registerBatchWithEmailPassword in auth store) to register users
for (const user of chunk) {
// Handle Email Registration
const {
Expand All @@ -361,15 +363,15 @@ async function submitStudents() {
...userData
} = user;
const computedEmail = email || `${username}@roar-auth.com`;
let sendObject = {
let studentObj = {
email: computedEmail,
password,
userData,
};
if (username) _set(sendObject, 'userData.username', username);
if (firstName) _set(sendObject, 'userData.name.first', firstName);
if (middleName) _set(sendObject, 'userData.name.middle', middleName);
if (lastName) _set(sendObject, 'userData.name.last', lastName);
if (username) _set(studentObj, 'userData.username', username);
if (firstName) _set(studentObj, 'userData.name.first', firstName);
if (middleName) _set(studentObj, 'userData.name.middle', middleName);
if (lastName) _set(studentObj, 'userData.name.last', lastName);

const orgNameMap = {
district: district,
Expand All @@ -380,7 +382,7 @@ async function submitStudents() {

// If orgType is a given column, check if the name is
// associated with a valid id. If so, add the id to
// the sendObject. If not, reject user
// the studentObj. If not, reject user
for (const [orgType, orgName] of Object.entries(orgNameMap)) {
if (orgName) {
let orgInfo;
Expand All @@ -396,7 +398,7 @@ async function submitStudents() {
}

if (!_isEmpty(orgInfo)) {
_set(sendObject, `userData.${orgType}`, orgInfo);
_set(studentObj, `userData.${orgType}`, orgInfo);
} else {
addErrorUser(user, `Error: ${orgType} '${orgName}' is invalid`);
if (processedUsers >= totalUsers) {
Expand All @@ -407,37 +409,45 @@ async function submitStudents() {
}
}

authStore
.registerWithEmailAndPassword(sendObject)
.then(() => {
toast.add({
severity: 'success',
summary: 'User Creation Success',
detail: `${sendObject.email} was sucessfully created.`,
life: 9000,
});
processedUsers = processedUsers + 1;
if (processedUsers >= totalUsers) {
activeSubmit.value = false;
if (errorUsers.value.length === 0) {
// Processing is finished, and there are no error users.
router.push({ name: 'Home' });
}
}
})
.catch((e) => {
toast.add({
severity: 'error',
summary: 'User Creation Failed',
detail: 'Please see error table below.',
life: 3000,
});
addErrorUser(user, e);
if (processedUsers >= totalUsers) {
activeSubmit.value = false;
}
});
students.push(studentObj);

// add each individual student Obj to the students array

// authStore
// .registerWithEmailAndPassword(studentObj)
// .then(() => {
// toast.add({
// severity: 'success',
// summary: 'User Creation Success',
// detail: `${studentObj.email} was sucessfully created.`,
// life: 9000,
// });
// processedUsers = processedUsers + 1;
// if (processedUsers >= totalUsers) {
// activeSubmit.value = false;
// if (errorUsers.value.length === 0) {
// // Processing is finished, and there are no error users.
// router.push({ name: 'Home' });
// }
// }
// })
// .catch((e) => {
// toast.add({
// severity: 'error',
// summary: 'User Creation Failed',
// detail: 'Please see error table below.',
// life: 3000,
// });
// addErrorUser(user, e);
// if (processedUsers >= totalUsers) {
// activeSubmit.value = false;
// }
// });
}
// TODO: process

// submit a batched array of students to register
authStore.registerBatchWithEmailPassword({ students: students });
await delay(2250);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/store/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ export const useAuthStore = () => {
async updateConsentStatus(docName, consentVersion) {
this.roarfirekit.updateConsentStatus(docName, consentVersion);
},
async registerBatchWithEmailPassword({ students }) {
console.log('batch user register called with students array: ', students);
return;
// return this.roarfirekit.registerBatchWIthEmailPassword(students);
},
async registerWithEmailAndPassword({ email, password, userData }) {
return this.roarfirekit.createStudentWithEmailPassword(email, password, userData);
},
Expand Down
Loading