Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgwill/d94420e2fac0710741f90e089601a645 to your computer and use it in GitHub Desktop.
Save jgwill/d94420e2fac0710741f90e089601a645 to your computer and use it in GitHub Desktop.
Function to get Users and Notes
var config = {
apiKey: "uouhtn,htnhutnaohtenuhoetnuhns",
authDomain: "uoeuoeu-eoueou.firebaseapp.com",
databaseURL: "https://oeuoeu-eoueue.firebaseio.com",
projectId: "oeuoeu-oeue",
storageBucket: "oeuoeu-oeuoeu.appspot.com",
messagingSenderId: "2342342343"
};
const functions = require('firebase-functions');
const tlid = require('tlid');
// The Firebase Admin SDK to access the Firebase Realtime Database.
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
//admin.initializeApp(config);
exports.notes = functions.https.onRequest((req, res) => {
// const uidFiltering = "";
// req.query.id ;
///notes
var db = admin.firestore();
var noteId = "4DjvJ4THAOHjC17V4iar";
var notesRef = db.collection("notes").doc(noteId);
var r = new Object();
r.version = "1.0.17";
console.log("-----------version:" + r.version);
r.id = noteId;
r.tlid = tlid.get();
var stuff = [];
db.collection("notes").get().then(snapshot => {
snapshot.forEach(doc => {
var key = doc.id;
var content =doc.data().content;
var time = doc.data().time;
var uid =doc.data().uid?doc.data().uid:"NULL";
var url=doc.data().url? doc.data().url:"NULL";
var newElement = {key,content,uid,url,time};
stuff = stuff.concat(newElement);
});
res.send(stuff)
return "";
}).catch(reason => {
res.send(reason)
})
});
exports.users = functions.https.onRequest((req, res) => {
// const uidFiltering = "";
// req.query.id ;
///notes
var db = admin.firestore();
var r = new Object();
r.version = "1.0.19";
console.log("-----------version:" + r.version);
r.tlid = tlid.get();
var stuff = [];
db.collection("users").get().then(snapshot => {
snapshot.forEach(doc => {
var key = doc.id;
var displayName =doc.data().displayName;
var email = doc.data().email;
var photoURL =doc.data().photoURL?doc.data().photoURL:"NULL";
var uid=doc.data().uid;
var newElement = {key,displayName,email,photoURL,uid};
stuff = stuff.concat(newElement);
});
res.send(stuff)
return "";
}).catch(reason => {
res.send(reason)
})
});
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "^7.0.0",
"firebase-functions": "^2.2.0",
"tlid": "^1.0.9"
},
"private": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment