-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Requirement builder with the new data format (#588)
- Loading branch information
1 parent
15502f2
commit b448fc0
Showing
18 changed files
with
365 additions
and
578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { overriddenFulfillmentChoicesCollection } from '../firebase-frontend-config'; | ||
import store from '../store'; | ||
|
||
export const updateRequirementChoice = ( | ||
courseUniqueID: string | number, | ||
choiceUpdater: (choice: FirestoreCourseOptInOptOutChoices) => FirestoreCourseOptInOptOutChoices | ||
): void => { | ||
overriddenFulfillmentChoicesCollection.doc(store.state.currentFirebaseUser.email).set({ | ||
...store.state.overriddenFulfillmentChoices, | ||
[courseUniqueID]: choiceUpdater( | ||
store.state.overriddenFulfillmentChoices[courseUniqueID] || { | ||
arbitraryOptIn: {}, | ||
acknowledgedCheckerWarningOptIn: [], | ||
optOut: [], | ||
} | ||
), | ||
}); | ||
}; | ||
|
||
export const updateRequirementChoices = ( | ||
updater: ( | ||
oldChoices: FirestoreOverriddenFulfillmentChoices | ||
) => FirestoreOverriddenFulfillmentChoices | ||
): void => { | ||
overriddenFulfillmentChoicesCollection | ||
.doc(store.state.currentFirebaseUser.email) | ||
.set(updater(store.state.overriddenFulfillmentChoices)); | ||
}; | ||
|
||
export const deleteCourseFromRequirementChoices = (courseUniqueID: string | number): void => | ||
deleteCoursesFromRequirementChoices([courseUniqueID]); | ||
|
||
export const deleteCoursesFromRequirementChoices = ( | ||
courseUniqueIds: readonly (string | number)[] | ||
): void => { | ||
const courseUniqueIdStrings = new Set(courseUniqueIds.map(uniqueId => uniqueId.toString())); | ||
overriddenFulfillmentChoicesCollection | ||
.doc(store.state.currentFirebaseUser.email) | ||
.set( | ||
Object.fromEntries( | ||
Object.entries(store.state.overriddenFulfillmentChoices).filter( | ||
([uniqueId]) => !courseUniqueIdStrings.has(uniqueId) | ||
) | ||
) | ||
); | ||
}; |
Oops, something went wrong.