diff --git a/src/pages/RegisterStudents.vue b/src/pages/RegisterStudents.vue index f2be680ad..850f7892d 100644 --- a/src/pages/RegisterStudents.vue +++ b/src/pages/RegisterStudents.vue @@ -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 { @@ -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, @@ -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; @@ -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) { @@ -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); } } diff --git a/src/store/auth.js b/src/store/auth.js index 74e791cc5..698481c8b 100644 --- a/src/store/auth.js +++ b/src/store/auth.js @@ -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); },