This file contains hidden or 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
| rules_version = '2'; | |
| service cloud.firestore { | |
| match /databases/{database}/documents { | |
| match /junction_student_course/{junctionId} { | |
| allow read: | |
| if request.auth != null | |
| && request.auth.uid == resource.data.studentId; | |
| allow create: | |
| if request.auth != null |
This file contains hidden or 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
| async function attendCourse(studentId, courseId) { | |
| const attendingRef = db.doc(`students/${studentId}/attending/${courseId}`); | |
| const attendeeRef = db.doc(`courses/${courseId}/attendees/${studentId}`); | |
| const batch = db.batch(); | |
| batch.set(attendingRef, {}); | |
| batch.set(attendeeRef, {}); | |
| await batch.commit(); | |
| } |
This file contains hidden or 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
| function countListener(onCountChange: (count: number) => void) { | |
| const query = firebase.firestore().collection("fruits"); | |
| let count = 0; | |
| return query.onSnapshot(snapshot => { | |
| snapshot.docChanges().forEach(change => { | |
| if (change.type === "added") onCountChange(++count); | |
| if (change.type === "removed") onCountChange(--count); | |
| }); | |
| }); | |
| } |
This file contains hidden or 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
| const admin = require("firebase-admin"); | |
| process.env["FIRESTORE_EMULATOR_HOST"] = "localhost:8080"; | |
| const serviceAccountKey = require("./serviceAccountKey.json"); | |
| admin.initializeApp({ | |
| credential: admin.credential.cert(serviceAccountKey), | |
| databaseURL: `https://${serviceAccountKey.project_id}.firebaseio.com`, | |
| }); |