Last active
June 6, 2018 10:01
-
-
Save YonathanMeguira/ea853fd9012751d54b2f5e4dd1dc3756 to your computer and use it in GitHub Desktop.
money bot --total expense
This file contains hidden or 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
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