Firebase access methods
General info
All functions receive a Firebase Database object as their first argument.
Example:
const db = firebase.database();
// ...
import { listenToAccount } from '@igemnace/firebase-access/lib/users';
listenToAccount(db, options);
All functions also receive necessary data through an object argument, which is usually given last.
Example:
import { updateSessionStatus } from '@igemnace/firebase-access/lib/sessions';
updateSessionStatus(db, {
sessionUid: 'abc123',
tutorUid: 'def456',
clientUid: 'ghi789',
clientType: 'student',
sessionStatus: 'accepted',
});
All fetching functions return a Promise resolving to an object. This object
contains two keys, data
for the data and next
for the next ID to be fetched
(used only for pagination).
Example:
import { getTutorSubjects } from '@igemnace/firebase-access/lib/tutors';
getTutorSubjects(db, options)
.then(result => console.log(result));
// will log result to console:
// {data: ['Math', 'Science'], next: null}
All listener functions receive success and error callbacks in the options
argument. The success callback receives an object with data
and next
keys
(the same format as for fetching functions), while the error callback receives
an error object.
Example:
import { listenToAccount } from '@igemnace/firebase-access/lib/users';
listenToAccount(db, {
uid,
success: result => console.log(result),
error: err => console.log(err),
});
// on success, will log result to console:
// {data: {name: 'Juan dela Cruz', ...}, next: null}
// on error, will log error to console:
// {message: 'Firebase read failed...'}
Functions are imported from lib/${filename}
.
Example:
// getTutors from tutors.js
import { getTutors } from '@igemnace/firebase-access/lib/tutors';
// getSessionDetails from sessions.js
import { getSessionDetails } from '@igemnace/firebase-access/lib/sessions';
The following sections will document each function in detail.
users.js
Function name | Description |
---|---|
stopListening | Removes all attached listeners. |
getAccountType | Fetches the account type of a given UID. |
listenToAccount | Attaches a listener that receives account data. |
listenToChildAccount | Attaches a listener that receives child account data. |
updateAccount | Updates account data. |
updateChildAccount | Updates child account data. |
Function arguments
- stopListening:
(db, uid)
- getAccountType:
(db, { uid })
- listenToAccount:
(db, { uid, success, error })
- listenToChildAccount:
(db, { parentUid, childUid, success, error })
- updateAccount:
(db, { uid, accountData })
- updateChildAccount:
(db, { parentUid, childUid, childAccountData })
tutors.js
Function name | Description |
---|---|
getTutors | Fetches all tutor display data. |
getTutorDetails | Fetches a single tutor's account data. |
getTutorsBySubjectPaginated | Fetches tutors teaching a given subject by page. |
getTutorSubjects | Fetches subjects taught by a given tutor. |
listenToTutorDetails | Attaches a listener that receives a tutor's details. |
getTutorSchedules | Fetches a tutor's preferred schedules. |
addTutorSchedule | Adds a new preferred schedule for a tutor. |
addMultipleTutorSchedules | Adds an array of new preferred schedules for a tutor. |
updateTutorScheduleStatus | Marks a tutor's schedule as free/taken. |
updateMultipleTutorSchedulesStatus | Marks an array of a tutor's schedules as free/taken. |
Function arguments
- getTutors:
(db)
- getTutorDetails:
(db, { tutorUid })
- getTutorsBySubjectPaginated:
(db, { subject, start })
- getTutorSubjects:
(db, { tutorUid })
- listenToTutorDetails:
(db, { tutorUid, success, error })
- getTutorSchedules:
(db, { tutorUid })
- addTutorSchedule:
(db, { tutorUid, scheduleData })
- addMultipleTutorSchedules:
(db, { tutorUid, scheduleDataArray })
- updateTutorScheduleStatus:
(db, { tutorUid, scheduleUid, scheduleStatus })
- updateMultipleTutorSchedulesStatus:
(db, { tutorUid, scheduleUidArray, scheduleStatus })
sessions.js
Function name | Description |
---|---|
stopListening | Removes all attached listeners. |
listenToSessions | Attaches a listener to sessions. |
getSessionDetails | Fetches a session's details. |
createSession | Creates a new session. |
updateSessionDetails | Updates an existing session's details. |
updateSessionStatus | Marks a session as accepted/rejected/canceled. |
deleteSession | Deletes all of a session's data. |
endSession | Finishes a session. |
cancelSession | Cancels a session properly. |
Function arguments
- stopListening:
(db, uid)
- listenToSessions:
(db, { uid, accountType, success, error })
- listenToSessionsAsStudent (deprecated):
(db, { uid, success, error })
- listenToSessionsAsTutor (deprecated):
(db, { uid, success, error })
- listenToSessionsAsParent (deprecated):
(db, { uid, success, error })
- getSessionDetails:
(db, { sessionUid })
- createSession:
(db, { sessionData, tutorUid, clientUid, clientType })
- updateSessionDetails:
(db, { sessionUid, sessionData })
- updateSessionStatus:
(db, { sessionUid, tutorUid, clientUid, clientType, sessionStatus })
- deleteSession:
(db, { sessionUid, tutorUid, clientUid, clientType })
- endSession:
(db, { sessionUid, tutorUid, clientUid, clientType, paymentData })
- cancelSession:
(db, { sessionUid, tutorUid, clientUid, clientType })
notifications.js
Function name | Description |
---|---|
stopListening | Removes all attached listeners. |
listenToNotifications | Attaches a listener to notifications. |
createNotification | Creates a new notification. |
deleteNotification | Deletes a notification. |
Function arguments
- stopListening:
(db, uid)
- listenToNotifications:
(db, { uid, success, error })
- createNotification:
(db, { uid, action, timestamp, notificationDetails })
- deleteNotification:
(db, { userUid, notificationUid })
locations.js
Function name | Description |
---|---|
stopListening | Removes all attached listeners. |
pushLocationEntry | Pushes a new "I'm Here" location entry for an ongoing session. |
Function arguments
- stopListening:
(db, uid)
- pushLocationEntry:
(db, { uid, locationData })