Skip to content

Commit

Permalink
changes for family
Browse files Browse the repository at this point in the history
  • Loading branch information
Emily-ejag committed Jan 16, 2024
1 parent cfcb904 commit 4b63e35
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 0 deletions.
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@
"lib/**/*"
],
"dependencies": {
"@bdelab/roar-firekit": "^4.1.1",
"crc-32": "^1.2.2",
"dot-object": "^2.1.4",
"firebase": "^9.23.0",
"link": "^2.1.0",
"lodash": "^4.17.21",
"vue": "^3.3.4"
}
Expand Down
136 changes: 136 additions & 0 deletions src/firestore/firekit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ import {
IAssessmentData,
IAssignedAssessmentData,
IAssignmentData,
IChildData,

Check failure on line 50 in src/firestore/firekit.ts

View workflow job for this annotation

GitHub Actions / Node lts/*

Module '"./interfaces"' has no exported member 'IChildData'.

Check failure on line 50 in src/firestore/firekit.ts

View workflow job for this annotation

GitHub Actions / Node 18

Module '"./interfaces"' has no exported member 'IChildData'.
IExternalUserData,
IFirekit,
IName,
IOrg,
IOrgLists,
IRoarConfigData,
IStudentData,
// ICreateParentInput,
IUserData,
OrgCollectionName,
UserType,
Expand All @@ -62,6 +64,7 @@ import { IUserInput } from './app/user';
import { RoarAppkit } from './app/appkit';
import { getOrganizations, getTaskAndVariant, getTasks, getVariants } from './query-assessment';
import { ITaskVariantInfo, RoarTaskVariant } from './app/task';
import { forEach } from 'lodash';

enum AuthProviderType {
CLEVER = 'clever',
Expand All @@ -77,6 +80,8 @@ const RoarProviderId = {
ROAR_ADMIN_PROJECT: 'oidc.gse-roar-admin',
};



interface ICreateUserInput {
dob: string;
grade: string;
Expand All @@ -102,6 +107,22 @@ interface ICreateUserInput {
group: { id: string; abbreviation?: string } | null;
}

interface ICreateParentInput{
name: {
first: string;
last: string;
};
}

//EMILY -> PLEASE CHECK THIS
export interface IChildData{
email: string,
password: string,
userData: ICreateUserInput,
familyId:string,
orgCode:string,
}

interface ICurrentAssignments {
assigned: string[];
started: string[];
Expand Down Expand Up @@ -1165,6 +1186,7 @@ export class RoarFirekit {

// TODO: this can probably be optimized.
_set(userDocData, 'email', email);

if (_get(userData, 'username')) _set(userDocData, 'username', userData.username);
if (_get(userData, 'name')) _set(userDocData, 'name', userData.name);
if (_get(userData, 'dob')) _set(userDocData, 'studentData.dob', userData.dob);
Expand All @@ -1185,6 +1207,39 @@ 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);
// }
// }





const cloudCreateAdminStudent = httpsCallable(this.admin!.functions, 'createstudentaccount');
const adminResponse = await cloudCreateAdminStudent({ email, password, userData: userDocData });
const adminUid = _get(adminResponse, 'data.adminUid');
Expand All @@ -1198,6 +1253,74 @@ export class RoarFirekit {
await cloudUpdateUserClaims({ adminUid, assessmentUid });
}



// async createNewFamily(email:string, password:string, caregiverData: ICreateParentInput, children:[ICreateUserInput]){
// // this._verifyAuthentication();
// // this._verifyAdmin();

// const userDocData: IUserData = {
// userType: UserType.caregiver,
// //studentData: {} as IStudentData,
// districts: emptyOrg(),
// schools: emptyOrg(),
// classes: emptyOrg(),
// families: emptyOrg(),
// groups: emptyOrg(),
// archived: false,
// };

// // const familyId = await this.createOrg('families',{name:`${userData.name.last}' family`});

// // _set(userDocData, 'orgIds.family', familyId);

// _set(userDocData, 'email', email);
// if (_get(caregiverData, 'name')) _set(userDocData, 'name', caregiverData.name);

// console.log("Sending parent UserDocData",userDocData);

// const cloudCreateAdminFamily = httpsCallable(this.admin!.functions, 'createnewfamily');
// const adminResponse = await cloudCreateAdminFamily({ email, password, userData: userDocData });
// const adminUid = _get(adminResponse, 'data.adminUid');

// const cloudCreateAppFamily = httpsCallable(this.app!.functions, 'createnewfamily');
// const appResponse = await cloudCreateAppFamily({ adminUid, email, password, userData: userDocData });
// // cloud function returns all relevant Uids (since at this point, all of the associations and claims have been made)
// const assessmentUid = _get(appResponse, 'data.assessmentUid');

// const cloudUpdateUserClaims = httpsCallable(this.admin!.functions, 'associateassessmentuid');
// await cloudUpdateUserClaims({ adminUid, assessmentUid });

// }

//EMILY - REVIEW THIS ---

async createNewFamily(caretakerEmail:string, caretakerPassword:string, caregiverData: ICreateParentInput, children:IChildData[]){

const cloudCreateFamily = httpsCallable(this.admin!.functions, 'createnewfamily');
const familyResponse = await cloudCreateFamily({
caretakerEmail,
caretakerPassword,

caregiverData,
children,
});

if (_get(familyResponse.data, 'status') !== 'ok') { //set status
throw new Error('Failed to create family.');
}

//EMILY -> PLEASE CHECK THIS
//maybe we can create childs here? and then we don't need to create new function
//because the parent already will be an admin here?

const createUserPromises = children.map(async (child) => {
await createUserWithEmailAndPassword(child.email, child.password, child.userData);
});

await Promise.all(createUserPromises);
}

async createStudentWithUsernamePassword(username: string, password: string, userData: ICreateUserInput) {
this._verifyAuthentication();
this._verifyAdmin();
Expand All @@ -1223,6 +1346,18 @@ 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 @@ -1282,6 +1417,7 @@ export class RoarFirekit {
}

async createOrg(orgsCollection: OrgCollectionName, orgData: IOrg) {

this._verifyAuthentication();
this._verifyAdmin();

Expand Down
4 changes: 4 additions & 0 deletions src/firestore/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export enum UserType {
caregiver = 'caregiver',
guest = 'guest',
researcher = 'researcher',
// parent = 'parent',
}

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



export interface IUserData extends DocumentData {
id?: string;
userType: UserType;
Expand Down Expand Up @@ -170,6 +173,7 @@ export interface IClass extends DocumentData {
}

export interface IFamily extends DocumentData {
name: string;
[x: string]: unknown;
}

Expand Down

0 comments on commit 4b63e35

Please sign in to comment.