Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert functions and variables to e6 syntax #352

Merged
merged 19 commits into from Aug 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 18 additions & 18 deletions firestore/scripts/FriendlyEats.Data.js
Expand Up @@ -15,39 +15,39 @@
*/
'use strict';

FriendlyEats.prototype.addRestaurant = function(data) {
var collection = firebase.firestore().collection('restaurants');
FriendlyEats.prototype.addRestaurant = (data) => {
const collection = firebase.firestore().collection('restaurants');
return collection.add(data);
};

FriendlyEats.prototype.getAllRestaurants = function(render) {
var query = firebase.firestore()
FriendlyEats.prototype.getAllRestaurants = (render) => {
const query = firebase.firestore()
.collection('restaurants')
.orderBy('avgRating', 'desc')
.limit(50);
this.getDocumentsInQuery(query, render);
};

FriendlyEats.prototype.getDocumentsInQuery = function(query, render) {
query.onSnapshot(function (snapshot) {
FriendlyEats.prototype.getDocumentsInQuery = (query, render) => {
query.onSnapshot((snapshot) => {
if (!snapshot.size) {
return render();
}

snapshot.docChanges().forEach(function(change) {
snapshot.docChanges().forEach((change) => {
if (change.type === 'added' || change.type === 'modified') {
render(change.doc);
}
});
});
};

FriendlyEats.prototype.getRestaurant = function(id) {
FriendlyEats.prototype.getRestaurant = (id) => {
return firebase.firestore().collection('restaurants').doc(id).get();
};

FriendlyEats.prototype.getFilteredRestaurants = function(filters, render) {
var query = firebase.firestore().collection('restaurants');
FriendlyEats.prototype.getFilteredRestaurants = (filters, render) => {
let query = firebase.firestore().collection('restaurants');

if (filters.category !== 'Any') {
query = query.where('category', '==', filters.category);
Expand All @@ -70,16 +70,16 @@ FriendlyEats.prototype.getFilteredRestaurants = function(filters, render) {
this.getDocumentsInQuery(query, render);
};

FriendlyEats.prototype.addRating = function(restaurantID, rating) {
var collection = firebase.firestore().collection('restaurants');
var document = collection.doc(restaurantID);
var newRatingDocument = document.collection('ratings').doc();
FriendlyEats.prototype.addRating = (restaurantID, rating) => {
const collection = firebase.firestore().collection('restaurants');
const document = collection.doc(restaurantID);
const newRatingDocument = document.collection('ratings').doc();

return firebase.firestore().runTransaction(function(transaction) {
return transaction.get(document).then(function(doc) {
var data = doc.data();
return firebase.firestore().runTransaction((transaction) => {
return transaction.get(document).then((doc) => {
const data = doc.data();

var newAverage =
const newAverage =
(data.numRatings * data.avgRating + rating.rating) /
(data.numRatings + 1);

Expand Down