1.5.2 • Published 7 years ago

@igemnace/firebase-access v1.5.2

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

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 nameDescription
stopListeningRemoves all attached listeners.
getAccountTypeFetches the account type of a given UID.
listenToAccountAttaches a listener that receives account data.
listenToChildAccountAttaches a listener that receives child account data.
updateAccountUpdates account data.
updateChildAccountUpdates 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 nameDescription
getTutorsFetches all tutor display data.
getTutorDetailsFetches a single tutor's account data.
getTutorsBySubjectPaginatedFetches tutors teaching a given subject by page.
getTutorSubjectsFetches subjects taught by a given tutor.
listenToTutorDetailsAttaches a listener that receives a tutor's details.
getTutorSchedulesFetches a tutor's preferred schedules.
addTutorScheduleAdds a new preferred schedule for a tutor.
addMultipleTutorSchedulesAdds an array of new preferred schedules for a tutor.
updateTutorScheduleStatusMarks a tutor's schedule as free/taken.
updateMultipleTutorSchedulesStatusMarks 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 nameDescription
stopListeningRemoves all attached listeners.
listenToSessionsAttaches a listener to sessions.
getSessionDetailsFetches a session's details.
createSessionCreates a new session.
updateSessionDetailsUpdates an existing session's details.
updateSessionStatusMarks a session as accepted/rejected/canceled.
deleteSessionDeletes all of a session's data.
endSessionFinishes a session.
cancelSessionCancels 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 nameDescription
stopListeningRemoves all attached listeners.
listenToNotificationsAttaches a listener to notifications.
createNotificationCreates a new notification.
deleteNotificationDeletes 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 nameDescription
stopListeningRemoves all attached listeners.
pushLocationEntryPushes a new "I'm Here" location entry for an ongoing session.

Function arguments

  • stopListening: (db, uid)
  • pushLocationEntry: (db, { uid, locationData })
1.5.2

7 years ago

1.5.1

7 years ago

1.5.0

7 years ago

1.4.3

7 years ago

1.4.2

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.7

7 years ago

1.2.6

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago