Created
June 24, 2014 17:24
-
-
Save gabrielhpugliese/15442c2ecc15b31cd46f 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
// COMO VC TEM Q FAZER: | |
Meteor.users.find().forEach(function (doc) { | |
if (doc.profile && doc.profile.phoneNumber) { | |
timmy++; | |
} else if (doc.profile && doc.profile.postCode && doc.stripe) { | |
kenny++; | |
} | |
}); | |
/*****************************************************************************/ | |
/* Counts Methods */ | |
/*****************************************************************************/ | |
Meteor.methods({ | |
counts:function() { | |
if (Roles.userIsInRole(this.userId, 'admin')) { | |
var | |
//general status | |
totalOrders = Orders.find().count(), | |
totalRevenue = _.reduce(Orders.find({status:'charged'}).fetch(), function (total, order) { | |
return total + Number(order.total); | |
},0), | |
withoutPromoRevenue = _.reduce(Orders.find({status:'charged'}).fetch(), function (total, order) { | |
if (order.discount) { | |
return total + (+order.total - +order.discount); | |
} else if (order.discounts) { | |
return total + (+order.total - +order.discounts); | |
} else { | |
return total + Number(order.total); | |
} | |
},0), | |
southPark = Meteor.users.find().count(), | |
//users status | |
timmy = Meteor.users.find({ 'profile.phoneNumber': { $exists: false }}).count(), | |
kenny = Meteor.users.find({$and:[{ 'profile.postCode': true }, { 'stripe': { $exists: false }}]}).count(), | |
butters = Meteor.users.find({$and:[{ 'profile.postCode': { $type: 2 }}, { 'stripe': { $exists: false }}]}).count(), | |
garrison = Meteor.users.find({$and:[{ 'profile.postCode': false }, { 'stripe': { $exists: true }}]}).count(), | |
cartman = Meteor.users.find({$and:[{ 'profile.postCode': true }, { 'stripe': { $exists: true }}]}).count(), | |
mephisto = _.reduce(Meteor.users.find({$and:[{ 'profile.postCode': true }, { 'stripe': { $exists: true }}]}).fetch(), function (total, user){ | |
var numberOrders = Orders.find({$and:[{idUser: user._id},{status: 'charged'}]}).count(); | |
if (+numberOrders === 1) { | |
return total + 1; | |
} else { | |
return 0; | |
} | |
},0), | |
token = _.reduce(Meteor.users.find({$and:[{ 'profile.postCode': true }, { 'stripe': { $exists: true }}]}).fetch(), function (total, user){ | |
var numbertoken = Orders.find({$and:[{idUser: user._id},{status: 'charged'}]}).count(); | |
if (+numbertoken > 1) { | |
return total + 1; | |
} else { | |
return 0; | |
} | |
},0), | |
//Orders status | |
confirmed = Orders.find({status: 'confirmed'}).count(), | |
picking = Orders.find({status: 'picking'}).count(), | |
collected = Orders.find({status: 'collected'}).count(), | |
delivering = Orders.find({status: 'delivering'}).count(), | |
delivered = Orders.find({status: 'delivered'}).count(), | |
charged = Orders.find({status: 'charged'}).count(), | |
canceled = Orders.find({status: 'canceled'}).count() | |
; | |
arrayCounts = [ | |
{ | |
totalOrders: totalOrders, | |
totalRevenue: totalRevenue, | |
withoutPromoRevenue:withoutPromoRevenue, | |
southPark: southPark, | |
timmy: timmy, | |
kenny: kenny, | |
butters: butters, | |
garrison: garrison, | |
cartman: cartman, | |
mephisto: mephisto, | |
token: token, | |
confirmed: confirmed, | |
picking: picking, | |
collected:collected, | |
delivering: delivering, | |
delivered: delivered, | |
charged: charged, | |
canceled:canceled | |
} | |
]; | |
return arrayCounts; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment