Last active
December 30, 2019 23:58
-
-
Save davidgilbertson/2988945ea2f075d8591613c985cd1c35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require('firebase-functions'); | |
const admin = require('firebase-admin'); | |
const uuid = require('uuid/v4'); | |
admin.initializeApp(functions.config().firebase); | |
const collection = admin.firestore().collection('all'); | |
module.exports = { | |
async create(data) { | |
const id = uuid(); | |
await collection.doc(id).create(data); | |
return id; | |
}, | |
async read(id) { | |
const docRef = await collection.doc(id).get(); | |
return docRef.exists ? docRef.data() : undefined; | |
}, | |
async update(id, data) { | |
// Update must fail if the specified item does not already exist | |
const docRef = await collection.doc(id).get(); | |
if (!docRef.exists) return false; | |
await collection.doc(id).set(data); | |
return true; | |
}, | |
async delete(id) { | |
return await collection.doc(id).delete(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment