# @igemnace/firebase-access

> ## General info

Latest version **1.5.2** (published 2017-06-07) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @igemnace/firebase-access
pnpm add @igemnace/firebase-access
yarn add @igemnace/firebase-access
bun add @igemnace/firebase-access
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.5.2 |
| Published | 2017-06-07 |
| First published | 2017-04-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Zac Emnace |
| Maintainers | igemnace |

## Links

- npm: https://www.npmjs.com/package/@igemnace/firebase-access
- npm.io page: https://npm.io/package/@igemnace/firebase-access

## Dependencies (6)

- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [babel-cli](https://npm.io/package/babel-cli.md) ^6.24.1
- [babel-polyfill](https://npm.io/package/babel-polyfill.md) ^6.23.0
- [babel-register](https://npm.io/package/babel-register.md) ^6.24.1
- [babel-preset-env](https://npm.io/package/babel-preset-env.md) ^1.4.0
- [babel-plugin-transform-object-rest-spread](https://npm.io/package/babel-plugin-transform-object-rest-spread.md) ^6.23.0

## Recent versions

- 1.5.2 (latest) — 2017-06-07
- 1.5.1 — 2017-06-06
- 1.5.0 — 2017-06-06
- 1.4.3 — 2017-06-06
- 1.4.2 — 2017-06-06
- 1.4.1 — 2017-06-06
- 1.4.0 — 2017-05-10
- 1.3.3 — 2017-05-05
- 1.3.2 — 2017-05-05
- 1.3.1 — 2017-05-05
- 1.3.0 — 2017-05-05
- 1.2.7 — 2017-05-03
- 1.2.6 — 2017-05-02
- 1.2.5 — 2017-05-02
- 1.2.4 — 2017-05-02
- … 6 more at https://npm.io/package/@igemnace/firebase-access/versions

## README

# Firebase access methods

## General info

All functions **receive a Firebase Database object as their first argument**.

Example:
```javascript
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:
```javascript
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:
```javascript
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:
```javascript
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:
```javascript
// 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 })`

---
_Source: https://npm.io/package/@igemnace/firebase-access · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
