@everlast-brands/collection
TypeScript icon, indicating that this package has built-in type declarations

2.2.1 • Public • Published

Everlast Brands - Collections

Collections are a middleware between firebase firestore and backend services. They make getting CRUD applications up and running very fast, however, they are extremely tightly coupled to google firestore.

Installation

yarn add @everlast-brands/collection
// or
npm install @everlast-brands/collection

Setup

import express from "express";
import * as admin from "firebase-admin";
import {Collection} from "@everlast-brands/collection";

// Configure firebase firestore

admin.initializeApp({
  databaseURL: process.env.DATABASE_URL,
  projectId: process.env.PROJECT_ID,
  storageBucket: process.env.STORAGE_BUCKET,
});

const DB = admin.firestore();
DB.settings({ ignoreUndefinedProperties: true });

const app = express();

// add collections to the server
app.use((req, res, next) => {
  req.collections = {
    user: new Collection('users', DB),
    messages: new Collection('messages', DB),
    // ...other collections
  }
})

// ...rest of app

Usage

app.post("/users", async (req, res) => {
  const userdata = req.body.user;

  const result = await req.collections.user.create(userdata);

  // if successfull send success
  // if error send failure
})

Readme

Keywords

none

Package Sidebar

Install

npm i @everlast-brands/collection

Weekly Downloads

0

Version

2.2.1

License

ISC

Unpacked Size

10.6 kB

Total Files

8

Last publish

Collaborators

  • eb_dev