Skip to content

Instantly share code, notes, and snippets.

@YonathanMeguira
Last active June 6, 2018 10:01
Show Gist options
  • Save YonathanMeguira/ea853fd9012751d54b2f5e4dd1dc3756 to your computer and use it in GitHub Desktop.
Save YonathanMeguira/ea853fd9012751d54b2f5e4dd1dc3756 to your computer and use it in GitHub Desktop.
money bot --total expense
const Firebase = require("./firebase.init");
const returnTotal = (UID, res) => {
const date = new Date();
const month = date.getMonth();
Firebase.FireDB.ref(UID)
.once("value")
.then(snapshot => {
const user = snapshot.val() || "undefined";
if (user !== "undefined") {
const currentMonthExpenses = user[month];
let totalExpense = 0;
for (let expense in currentMonthExpenses){
totalExpense += parseInt(currentMonthExpenses[expense].amount);
}
const answer = `Since the begining of the month you've spent ${totalExpense} ₪`;
const message = {"messages": [{"text": answer}]};
res.send(message);
} else {
const answer = 'Hm, it looks like I do not know you ';
const message = {"messages": [{"text": answer}]};
res.send(message);
}
})
}
const doTheMath = (UID, res) => {
const date = new Date();
const day = date.getDate();
res.send(day);
}
module.exports = {returnTotal, doTheMath};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment