<commit_before>var usersApi = require('./usersApi');
var Firebase = require('firebase');
var FirebaseMarkersUrl = 'https://ralli.firebaseio.com/markers';
var MarkersRef = new Firebase(FirebaseMarkersUrl);


var markersApi = {
  createMarker: function() {

  }

}

module.exports = markersApi;<commit_msg>Add markers api<commit_after>var usersApi = require('./usersApi');
var Firebase = require('firebase');
var FirebaseMarkersUrl = 'https://ralli.firebaseio.com/markers';
var MarkersRef = new Firebase(FirebaseMarkersUrl);


var markersApi = {
  createMarker: function(currentUserId, eventTitle, eventAddress, eventLat, eventLong, eventDescription, eventTime, invitedGroupId, publicEvent) {

    if(publicEvent) {
      MarkersRef.push({
        creator: currentUserId,
        title: eventTitle,
        address: eventAddress,
        latitude: eventLat,
        longitude: eventLong,
        description: eventDescription,
        timeStart: eventTime,
        isPublic: true
      }).then((res) => {
        this.updateUserMarker(res.key(), currentUserId);
      })

    }else {
      MarkersRef.push({
        creator: currentUserId,
        title: eventTitle,
        address: eventAddress,
        latitude: eventLat,
        longitude: eventLong,
        description: eventDescription,
        timeStart: eventTime,
        isPublic: false,
        groupId: invitedGroupId
      }).then((res) => {
        this.updateUserMarker(res.key(), currentUserId);
      })
    }

  },

  updateUserMarker: function(markerId, currentUserId) {
    new Firebase('https://ralli.firebaseio.com/users/' + currentUserId).once('value').then((res) => {
      var userMarkers = res.val().markers;
      if(userMarkers) {
        userMarkers.push(markerId)
        new Firebase('https://ralli.firebaseio.com/users/' + currentUserId)
          .update({markers: userMarkers.slice(0)})

      }else {
        new Firebase('https://ralli.firebaseio.com/users/' + currentUserId)
          .update({markers: [markerId]})
      }
    })
  },

  getAllMarkers: function() {
    return MarkersRef.once('value').then((res) => res.val());
  },

  getMarkerLatlng: function(address) {
    address = address.toLowerCase().trim();
    var url = "https://maps.googleapis.com/maps/api/geocode/json?address=" + address + "&key=<KEY>"
    return fetch(url).then((res) => res.json());
    // when using this method chain with this code to get the laglng in an object
    // then((res) => console.log(res.results[0].geometry.location))
  }
}

module.exports = markersApi;


// markersApi.createMarker("-KHqf2KiolbegdEhXHuy")
// console.log(markersApi.getAllMarkers().then((res) => {console.log(res)}))

// console.log(markersApi.getMarkerLatlng("633 folsom san francisco").then((res) => {console.log(res)}));





{'fraction_non_alphanumeric': 0.1449119021934556, 'fraction_numerical': 0.002157497303128371, 'mean_word_length': 3.306501547987616, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 12, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2062519', 'n_tokens_mistral': 879, 'n_tokens_neox': 857, 'n_words': 155}