Skip to content

Commit

Permalink
Adding function to call cloud function
Browse files Browse the repository at this point in the history
  • Loading branch information
Zio-4 committed Feb 29, 2024
1 parent 62b3d5c commit 780d11f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 112 deletions.
149 changes: 40 additions & 109 deletions src/firestore/firekit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import {
IOrgLists,
IRoarConfigData,
IStudentData,
// ICreateParentInput,
IUserData,
OrgCollectionName,
UserType,
Expand All @@ -74,13 +73,6 @@ enum AuthProviderType {
EMAIL = 'email',
USERNAME = 'username',
}

const RoarProviderId = {
...ProviderId,
CLEVER: 'oidc.clever',
ROAR_ADMIN_PROJECT: 'oidc.gse-roar-admin',
};

interface ICreateUserInput {
dob: string;
grade: string;
Expand Down Expand Up @@ -133,14 +125,18 @@ export interface IRequestConfig {
}

interface LevanteUserData {
id: string,
userType: string,
childId: string,
parentId: string,
teacherId: string,
month: string,
year: string
group: string[]
id: string;
userType: string;
childId: string;
parentId: string;
teacherId: string;
month: string;
year: string;
group: string[];
}

interface LevanteSurveyResponses {
[key: string]: string;
}

export class RoarFirekit {
Expand Down Expand Up @@ -428,16 +424,17 @@ export class RoarFirekit {

async logInWithEmailAndPassword({ email, password }: { email: string; password: string }) {
this._verifyInit();
return signInWithEmailAndPassword(this.admin!.auth, email, password).then(() => {
return signInWithEmailAndPassword(this.app!.auth, email, password)
.then(this._setUidCustomClaims.bind(this))
.catch((error: AuthError) => {
console.error('(Inside) Error signing in', error);
});
})
.catch((error: AuthError) => {
console.error('(Outside) Error signing in', error);
});
return signInWithEmailAndPassword(this.admin!.auth, email, password)
.then(() => {
return signInWithEmailAndPassword(this.app!.auth, email, password)
.then(this._setUidCustomClaims.bind(this))
.catch((error: AuthError) => {
console.error('(Inside) Error signing in', error);
});
})
.catch((error: AuthError) => {
console.error('(Outside) Error signing in', error);
});
}

async logInWithUsernameAndPassword({ username, password }: { username: string; password: string }) {
Expand Down Expand Up @@ -1229,19 +1226,10 @@ export class RoarFirekit {
// }
}

// TODO: Create types for these functions
async createLevanteUsersWithEmailPassword(userData: LevanteUserData) {
this._verifyAuthentication();
this._verifyAdmin();

const cloudCreateLevanteUsers = httpsCallable(this.admin!.functions, 'createLevanteUsers');
return await cloudCreateLevanteUsers({ userData });
}

async createStudentWithEmailPassword(email: string, password: string, userData: ICreateUserInput) {
this._verifyAuthentication();
this._verifyAdmin();

if (!_get(userData, 'dob')) {
throw new Error('Student date of birth must be supplied.');
}
Expand Down Expand Up @@ -1304,67 +1292,6 @@ export class RoarFirekit {
if (_get(userData, 'group')) _set(userDocData, 'orgIds.group', userData.group!.id);
if (_get(userData, 'family')) _set(userDocData, 'orgIds.family', userData.family!.id);

//EMILY -> MAYBE COULD BE OPTIMIZED LIKE THIS --PLEASE REVIEW :)
// const userDdataInfotmation = {
// username: 'username',
// name: 'name',
// dob: 'studentData.dob',
// gender: 'studentData.gender',
// grade: 'studentData.grade',
// state_id: 'studentData.state_id',
// hispanic_ethnicity: 'studentData.hispanic_ethnicity',
// ell_status: 'studentData.ell_status',
// iep_status: 'studentData.iep_status',
// frl_status: 'studentData.frl_status',
// race: 'studentData.race',
// home_language: 'studentData.home_language',
// district: 'orgIds.district',
// school: 'orgIds.school',
// class: 'orgIds.class',
// group: 'orgIds.group',
// family: 'orgIds.family',
// };

// for (const [userDataItem, userDataItemPath] of Object.entries(userDdataInfotmation)) {
// const value = _get(userData, userDataItem);
// if (value !== undefined) {
// _set(userDocData, userDataItemPath, value);
// }
// }


//EMILY -> MAYBE COULD BE OPTIMIZED LIKE THIS --PLEASE REVIEW :)
// const userDdataInfotmation = {
// username: 'username',
// name: 'name',
// dob: 'studentData.dob',
// gender: 'studentData.gender',
// grade: 'studentData.grade',
// state_id: 'studentData.state_id',
// hispanic_ethnicity: 'studentData.hispanic_ethnicity',
// ell_status: 'studentData.ell_status',
// iep_status: 'studentData.iep_status',
// frl_status: 'studentData.frl_status',
// race: 'studentData.race',
// home_language: 'studentData.home_language',
// district: 'orgIds.district',
// school: 'orgIds.school',
// class: 'orgIds.class',
// group: 'orgIds.group',
// family: 'orgIds.family',
// };

// for (const [userDataItem, userDataItemPath] of Object.entries(userDdataInfotmation)) {
// const value = _get(userData, userDataItem);
// if (value !== undefined) {
// _set(userDocData, userDataItemPath, value);
// }
// }





const cloudCreateStudent = httpsCallable(this.admin!.functions, 'createstudentaccount');
await cloudCreateStudent({ email, password, userData: userDocData });
}
Expand Down Expand Up @@ -1443,18 +1370,6 @@ export class RoarFirekit {
}
}

// async createFamily(email:string,
// password:string,
// caregiverData: ICreateParentInput,
// children:[{
// childrenData: ICreateUserInput,
// email: string,
// password: string,
// orgCode:string,
// }]){
// const cloudCreateFamily = httpsCallable(this.admin!functions, '')
// }

async getTasks(requireRegistered = true) {
this._verifyAuthentication();
return getTasks(this.app!.db, requireRegistered);
Expand Down Expand Up @@ -1593,4 +1508,20 @@ export class RoarFirekit {

return task;
}

// LEVANTE
async createLevanteUsersWithEmailPassword(userData: LevanteUserData) {
this._verifyAuthentication();
this._verifyAdmin();

const cloudCreateLevanteUsers = httpsCallable(this.admin!.functions, 'createLevanteUsers');
return await cloudCreateLevanteUsers({ userData });
}

async saveSurveyResponses(surveyResponses: LevanteSurveyResponses) {
this._verifyAuthentication();

const cloudSaveSurveyResponses = httpsCallable(this.admin!.functions, 'saveSurveyResponses');
return await cloudSaveSurveyResponses({ surveyResponses });
}
}
3 changes: 0 additions & 3 deletions src/firestore/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export enum UserType {
caregiver = 'caregiver',
guest = 'guest',
researcher = 'researcher',
// parent = 'parent',
}

export interface IExtraMetadata extends DocumentData {
Expand Down Expand Up @@ -76,8 +75,6 @@ export interface IName {
last: string;
}



export interface IUserData extends DocumentData {
id?: string;
userType: UserType;
Expand Down

0 comments on commit 780d11f

Please sign in to comment.