# firebase-ts-class

> Modulo en forma de clases para firebase

Latest version **1.0.3** (published 2019-12-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install firebase-ts-class
pnpm add firebase-ts-class
yarn add firebase-ts-class
bun add firebase-ts-class
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2019-12-16 |
| First published | 2019-12-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 19.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ivan Lozada Mendez |
| Maintainers | ivanlozada |

## Links

- npm: https://www.npmjs.com/package/firebase-ts-class
- npm.io page: https://npm.io/package/firebase-ts-class

## Dependencies (1)

- [firebase-admin](https://npm.io/package/firebase-admin.md) ^8.6.0

## Recent versions

- 1.0.3 (latest) — 2019-12-16
- 1.0.2 — 2019-12-15
- 1.0.1-beta1 — 2019-12-15
- 1.0.1-beta — 2019-12-15
- 1.0.1 — 2019-12-07
- 1.0.0 — 2019-12-07

## README

# Modulo para usar las herramientas de Firebase

## Importar el modulo
```
import {module} from 'firebase-ts-class';
```

## Firestore

- Para usar el modulo de `Firestore` se debe crear el objeto `Firestore`
```
const config = {
    projectId: '',  // project id
    keyFilename: '' // path service account
};
const Firestore = new module.Firestore(config);
```


### Funciones 

- Agregar nuevo documento 
`add(ref, data)`
```
const ref = 'nombreColeccion/idDocumento/nombreColeccion_2/idDocumento_2...';
data = {
    llave: 'valor',
    ...
    llaveN: 'valorN'
};

Firestore.add(ref, data);
await Firestore.add(ref, data);
```
- Actualizar documento
`update(ref, data)`
```
// En esta funcion siempre se debe hacer uso del idDocumento
const ref = 'nombreColeccion/idDocumento/nombreColeccion_2/idDocumento_2...';
data = {
    llave: 'valor',
    ...
    llaveN: 'valorN'
};

Firestore.update(ref, data);
await Firestore.update(ref, data);
```
- Obtener uno o varios documentos
`get(ref)`
```
const ref = 'nombreColeccion/idDocumento/nombreColeccion_2/idDocumento_2...';

Firestore.get(ref);
await Firestore.get(ref);
```
- Obtener sub colecciones
`getGroup(nombreColeccion)`
```
const nombreColeccion = 'subColeccion';

Firestore.getGroup(nombreColeccion);
await Firestore.getGroup(nombreColeccion);
```
- Obtener sub colecciones con filtros
`getGroupQuery(nombreColeccion, query)`
```
const nombreColeccion = 'subColeccion';
const query = [
    {
        campo: 'nombreCampo',
        valor: 'valor',
        operador: '[operador]'
    },
    ...
    {
        campo: 'nombreCampoN',
        valor: 'valorN',
        operador: '[operadorN]'
    }
]

//operadores validos '==', '<=', '>=', '<', '>', 'array-contains'

Firestore.getGroupQuery(nombreColeccion, query);
await Firestore.getGroupQuery(nombreColeccion, query);
```
- Obtener documentos por query
`getQuery(ref, query)`
```
const ref = 'nombreColeccion/idDoc..../nombreColeccionN';
const query = [
    {
        campo: 'nombreCampo',
        valor: 'valor',
        operador: '[operador]'
    },
    ...
    {
        campo: 'nombreCampoN',
        valor: 'valorN',
        operador: '[operadorN]'
    }
]

//operadores validos '==', '<=', '>=', '<', '>', 'array-contains'
//La referencia solo debe llegar hasta el nombre de la coleccion

Firestore.getQuery(ref, query);
await Firestore.getQuery(ref, query);
```

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