Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const functions = require('firebase-functions');
- const admin = require('firebase-admin');
- admin.initializeApp(functions.config().firebase);
- // // Create and Deploy Your First Cloud Functions
- // // https://firebase.google.com/docs/functions/write-firebase-functions
- //
- // exports.helloWorld = functions.https.onRequest((request, response) => {
- // response.send("Hello from Firebase!");
- // });
- // Docs: https://firebase.google.com/docs/functions/http-events
- // use this for calling this function: curl -X POST -H "Content-Type:application/json" -d '{"city":"Naples"}' https://us-central1-sportme-4e614e.cloudfunctions.net/getMatch?city=Naples
- exports.getMatch = functions.https.onRequest((req,res) => {
- const myCity = req.query.city
- console.log("Matching for my city: " + myCity)
- b = [ 5, 5 ]
- var match = []
- admin.database().ref().child('users/').once('value').then(function(snapshot) {
- //for ( u in snapshot.val() ) {
- snapshot.forEach(function(user){
- //console.log( user.key )
- //console.log( user.val() )
- // Only matches people from my city
- //console.log(" - " + user.val().city )
- if ( myCity.localeCompare( user.val().city ) == 0 ) {
- var x = b[0]*user.val().fitness + b[1]*user.val().goal
- var obj = { mVal: x, user: user.key }
- //console.log(" ++ " + obj)
- match.push( obj )
- //console.log(match)
- }
- //})
- })
- match.sort(function(a,b){
- return a.mVal < b.mVal
- })
- //console.log(match)
- res.status(200).send(match)
- })
- //console.log("match result" + match)
- })
- //TODO: when matching by tags, if there's no match, just proceed with matching by city
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement